我正在寻找一种方法来列出目录本身的目录中的所有文件以及这些子目录中的文件。

因此,如果我有:

./test.log
./test2.log
./directory
./directory/file2

我想要一个返回的命令:./test.log ./test2.log,而别无其他。

有帮助吗?

解决方案

如果你想 test.log, test2.log, , 和 file2 然后:

find . -type f

如果你不想要 file2 然后:

find . -maxdepth 1 -type f

其他提示

如果您还需要列出的文件系统的符号链接,管道,设备文件和其他特定元素,则应使用:

find -maxdepth 1 -not -type d

这将列出除目录以外的所有内容。

使用查找很简单,如:

find . -maxdepth 1 -type f
find . -type f
find /some/directory -type f
$ find . -type f -print

每个文件将在自己的行上。您必须在要搜索的目录中。

另一种选择

ls -ltr | grep ^d
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top