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
您可以使用该maxdepth
选项来限制递归。
find ./ -type f -maxdepth 1
从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
应该做你想做的
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 ;