【问题标题】:ignore directories in the find command忽略 find 命令中的目录
【发布时间】:2015-04-14 20:44:33
【问题描述】:

如何忽略 find 命令中的目录

find /testfile1

/testfile1
/testfile1/tmp1.txt
/testfile1/tmp2.txt
/testfile1/tmp3.txt
/testfile1/tmp4.txt
/testfile1/test1
/testfile1/test1/as
/testfile1/test1/dw
/testfile1/test2
/testfile1/test2/adsad
/testfile1/test2/bc

/testfile1 、 /testfile1/test1 和 /testfile1/test2 是目录。所以我想删除结果中的那些目录,我不能使用 type -f 因为我需要获取文件的完整路径。

那么我如何才能获得具有完整路径的文件,例如

/testfile1/tmp1.txt
/testfile1/tmp2.txt
/testfile1/tmp3.txt
/testfile1/tmp4.txt
/testfile1/test1/as
/testfile1/test1/dw
/testfile1/test2/adsad
/testfile1/test2/bc

谢谢

【问题讨论】:

    标签: linux awk sed grep find


    【解决方案1】:
    -type f
    

    作为测试,只会返回常规文件

    【讨论】:

    • 我认为这值得一票否决,因为问题明确表示他不能使用-type f
    【解决方案2】:

    仅排除目录:

    find /testfile1 ! -type d
    

    这将包括符号链接和各种其他非常规文件。

    【讨论】:

    • 谢谢。为什么我没想到:)
    • 某些 shell 可能会将 ! 解释为搜索命令历史记录的请求。我推荐find /testfile1 -not -type d
    • @AdamKatz 是的。改了。
    • @Wintermute 可读性始终值得商榷,但除此之外,! 应该始终是首选。它是 posix,-not 不是。我也不知道有什么贝壳可以治疗 ` ! ` 作为命令历史扩展(如果有人这样做,你可以逃避它)
    • @AdamKatz 哪个 shell 处理 ` ! ` 作为历史扩展的参数?
    猜你喜欢
    • 1970-01-01
    • 2013-02-05
    • 2016-05-22
    • 2016-04-21
    • 2018-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-11
    相关资源
    最近更新 更多