我构建了以下查找命令:
find ./ \( -path "*work*" -o -path "*ncvlog_lib*" \) -prune -o -type f -not
-name "*.wlf" -not -name "*.vcd" -not -name "*.sim" -not -name "*vcs*"
Run Code Online (Sandbox Code Playgroud)
该命令在一行中调用。为了便于阅读,我在这里断了线。
唯一的问题是,尽管提供了 -type f 参数,但它还是打印了修剪后的目录名称。示例输出:
./cdl2verilog_files/test_synth/work
./cdl2verilog_files/test_synth/some_file1.txt
./cdl2verilog_files/test_synth/something_else.txt
./cdl2verilog_files/test_synth/another_file.v
Run Code Online (Sandbox Code Playgroud)
work
是一个目录。它的内容不包含在输出中,因此修剪可以根据需要进行。但是,目录本身会被打印出来。我似乎无法找到解决方案。有什么想法吗?
顺便说一句,我正在使用 tcsh。
-prune
排除目录的内容,但不排除目录本身。如果这是命令中的-prune
唯一操作find
,则会发生这种情况。如果有任何其他操作(例如-exec
或-print
),则不会输出修剪后的目录名称。所以你只需要-print
在命令末尾添加一个显式的find
。例如:
find ./ \( -path "*work*" -o -path "*ncvlog_lib*" \) -prune -o -type f \
-not -name "*.wlf" -not -name "*.vcd" -not -name "*.sim" -not -name "*vcs*" \
-print
Run Code Online (Sandbox Code Playgroud)
find
顺便说一句,您可以通过使用单个-regex
谓词而不是多个-name
谓词来缩短/简化命令。例如
find ./ \( -path "*work*" -o -path "*ncvlog_lib*" \) -prune -o -type f \
-regextype awk -not -regex '.*\.(wlf|vcd|sim)$|.*vcs.*' -print
Run Code Online (Sandbox Code Playgroud)
这会产生与上面第一个版本相同的输出。