我编写了一个 find 函数,它在给定路径中的每个文件中搜索一个字符串,同时跳过我不想搜索的目录名称列表。我已经把这个脚本放在我的 .bashrc 文件中,像这样调用:
findTEXTinFILES /path/to/search 'text-to-find'
Run Code Online (Sandbox Code Playgroud)
find 部分效果很好,它为搜索文本着色,使其在视觉上脱颖而出!,但我无法让它跳过用 -prune 列出的目录。我已经阅读了我能找到的所有帖子,但没有一个对我有用。我尝试了多种变体,但都没有运气。所以我有几个问题:
-name和-path标准吗?我的服务器是带有 bash shell 的 CENTOS 6.9 virtuozzo。
function findTEXTinFILES {
find "$1" ! \( -name .bash_history -prune \
-o ! -path tmp -prune \
-o ! -path short -prune \
-o ! -path "*/_not_used/*" -prune \
-o ! -path backups -prune \
-o ! -path temp_logs -prune \
-o ! -name .cpan -prune \
-o ! -name .cpobjcache -prune \ …Run Code Online (Sandbox Code Playgroud)