在 linux 中仅列出数字目录名称

List only numerical directory names in linux

如何在 Linux 中仅列出数字目录名称。 只有目录,只有数字字符?

在 bash 中,您可以受益于扩展的 globbing:

shopt -s extglob
ls -d +([0-9])/

在哪里

+(pattern-list)

Matches one or more occurrences of the given patterns

末尾的 / 将列表限制为目录,-d 阻止 ls 列出其内容。

有多种解决方案。

1.You 可以只列出目录然后删除。和/从名字然后Grep只是数字:

ls -d ./*/ | sed 's/\.\///g' | sed 's/\///g' | grep -E '^[0-9]+$'

2.By "ls" & "grep" & 然后 "awk"。只需列出详细信息,Grep dirs,然后打印第 9 列:

ls -llh | grep '^d' | awk '{print }'

祝你在Arbaeen好运。