仅列出bash中目录和子目录中的文件名 [英] List only file names in directories and subdirectories in bash
本文介绍了仅列出bash中目录和子目录中的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在目录及其所有子目录中创建文件列表.我用过
I need to create a list of files in a directory and all of its subdirectories. I've used
find . -type f
获取文件列表,但是我只需要文件名,而不是指向它的路径.
to get the list of files, but I only need the file name, not the path that leads to it.
所以不要返回这个:
./temp2/temp3/file3.txt
./temp2/file2.txt
./file.txt
我需要回来
file3.txt
file2.txt
file.txt
推荐答案
find . -type f -exec basename {} \;
或更妙的是:
find . -type f -printf "%f\n"
这篇关于仅列出bash中目录和子目录中的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文