【问题标题】:In Ksh Shell use FIND to search through symbolic links but ignore certain directories在 Ksh Shell 中使用 FIND 搜索符号链接但忽略某些目录
【发布时间】:2012-05-12 09:14:59
【问题描述】:

我正在尝试在文件系统中搜索 *.csv 文件。我正在浏览的某些目录中有符号链接,但我想忽略某些目录,因为它们会导致令人讨厌的长时间耗时循环。

find -L "location" -name "*.csv >> find_result.txt

我如何告诉 find 忽略某些目录,同时继续查看其他目录中的符号链接。

【问题讨论】:

    标签: shell unix find ksh


    【解决方案1】:

    使用-prune 告诉find 不要进入给定目录。例如:

    find -L location -name 'dontLookHere' -prune \
                  -o -name 'orThereEither' -prune \
                  -o -name '*.csv' -print
    

    【讨论】:

    • 我使用 find /usr/abc -L -name './ignore_dir' -prune -o -name "*.csv" -print >> myfiles.txt 但它仍然给我一条错误消息说 find: bad option -L。 -L 和 Prune 可以同时使用吗
    • 对不起,@user1035818 - 必须先放 -L,因为它是一个选项,而不是谓词。上面固定。
    • 另外,-name 采用裸文件名;如果您想在特定的 pthanames 处进行修剪(例如“./ignore_dir”,但继续深入到任何其他恰好名为“ignore_dir”的目录),请改用-path
    • 没有使用路径,而是使用 -name " * dirname *"。谢谢回复,终于可以用了
    【解决方案2】:
    find dir -wholename dirtoskip -prune -o [rest of your find command]
    

    find dir \( -wholename dirtoskip -o -wholename another \) -prune -o [rest of your find command]
    

    【讨论】:

    • 可能很好,除了它不遵循符号链接,但-wholename 的可移植性不如-path,因为 find(1) 的更多版本支持后者而不是前者。 (虽然仍有旧版本不支持其中任何一个......)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2010-12-19
    • 1970-01-01
    • 2022-01-02
    相关资源
    最近更新 更多