在Shell中,可以使用find命令来递归遍历文件夹。下面是一个简单的例子:
find /path/to/directory -type f
这条命令将递归地遍历/path/to/directory文件夹及其所有子文件夹,并列出所有的文件。如果你只想列出目录而不包括文件,可以使用-type d参数:
find /path/to/directory -type d
你也可以在find命令中加入其他参数来进一步过滤文件或目录,例如按文件名进行过滤:
find /path/to/directory -type f -name "*.txt"
这条命令将只列出.txt后缀的文件。你还可以使用-exec参数来对找到的文件进行操作,例如删除所有.txt文件:
find /path/to/directory -type f -name "*.txt" -exec rm {} \;
记得在使用find命令时要小心,确保你知道你在做什么,以免不小心删除了重要文件。