Lin*_*nda 45 tree command-switch
您能否举一个使用 tree 命令过滤结果的示例,如下所示:
bin
,unitTest
).cpp
, .c
, .hpp
, .h
)小智 69
一种方法是将模式与-I
和-P
开关一起使用:
tree -f -I "bin|unitTest" -P "*.[ch]|*.[ch]pp." your_dir/
Run Code Online (Sandbox Code Playgroud)
在-f
每个文件打印的完整路径,并且-I
不包括在模式中的文件通过这里竖线分隔。该-P
开关仅包含与特定扩展名匹配的模式中列出的文件。
usefind
和tree
命令是使用 findprune
来排除搜索目录并用于tree -P
搜索模式。
使用 prune 开关,例如,如果您想排除misc
目录,只需-path ./misc -prune -o
在 find 命令中添加 a 即可。
例如。find . -path ./misc -prune -o -exec tree -P <pattern> {} \;
或者你可以使用-name "*.cpp" in find
用于排除多个目录使用
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o