1

I wonder whether there is some option in find or ls to print just files and not directories in the working directory.

find ./ -type f 

prints all files recursively, but what i need is just files in this folder

thanks in advance

4

3 回答 3

3

您可以使用该maxdepth选项来限制递归。

find ./ -type f -maxdepth 1
于 2013-04-30T18:50:14.417 回答
3

man find

-maxdepth  
   Descend at most levels (a non-negative integer) levels of directories below the 
   command line arguments. `-maxdepth 0' means only apply the tests and actions to the    
   command line arguments.

find . -type f -maxdepth 1 应该做你想做的

于 2013-04-30T18:51:17.273 回答
1

find包括您可能不想要的隐藏点文件。

此解决方案使用 ls 命令作为输入数组,在通过管道传输到 grep 的每个条目上调用 ls -ld 以排除目录,并将输出发送为 null,如果成功则回显原始输入:

for list in `ls` ; do ls -ld $list | grep -v ^d > /dev/null && echo $list ; done ;

您可以反转 grep 和条件输出,结果相同:

for list in `ls` ; do ls -ld $list | grep ^d > /dev/null || echo $list ; done ;
于 2013-10-07T09:08:01.783 回答