我正在寻找一种方法来列出目录中的所有文件,不包括目录本身,以及这些子目录中的文件。
所以如果我有:
./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 很简单:
find . -maxdepth 1 -type f
find . -type f
find /some/directory -type f
$ find . -type f -print
每个文件将在其自己的行上。您必须位于要搜索的目录中。
另一种选择
ls -ltr | grep ^d