在Linux中,如果你想在使用find
命令排除特定子目录时,可以使用-prune
选项
find . -type d -name 'exclude_dir' -prune -o -type f -print
这个命令的解释如下:
find .
:从当前目录开始搜索。-type d
:只查找目录。-name 'exclude_dir'
:查找名为exclude_dir
的目录。-prune
:当找到匹配的目录时,排除(prune)该目录及其子目录。-o
:逻辑或(OR),用于组合多个表达式。-type f
:只查找文件。-print
:打印匹配的文件路径。这个命令将输出除名为exclude_dir
的子目录及其子目录之外的所有文件的路径。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:linux如何创建子目录