我有一个包含多个子目录的目录。我只想列出包含至少一个文件的子目录。我怎么能这样做?

有帮助吗?

解决方案

 find . -mindepth 1 -maxdepth 1 -not -empty -type d

将为您提供所有非空目录。如果要排除仅包含其他目录(但没有文件)的目录,其他一个答案可能会更好......

其他提示

find . -type f -print0 | xargs -0 -n 1 dirname | sort -u

怎么样:

find /nominated/directory -type f |
sed 's%/[^/]*$%% |
sort -u

查找文件 - 删除文件名部分 - 唯一排序。

它不会列出仅包含其他子子目录的子目录。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top