【问题标题】:how to process linux find command didn't has result如何处理 linux find 命令没有结果
【发布时间】:2012-12-24 09:13:22
【问题描述】:

找到 . -name "*.pyc" -print0| xargs -0 rm

我使用这个命令删除 python 编译的文件但是如果当前目录没有任何 *.pyc 文件这个 cmd 将不起作用 用 rm 命令打印出错误需要运算符 args

如果当前目录没有*.pyc文件这种情况如何处理?

【问题讨论】:

    标签: bash find xargs rm


    【解决方案1】:

    使用查找-exec:

    find -name '*.pyc' -exec rm {} \;
    

    或丢弃输出技术:

    find . -name "*.pyc" -print0| xargs -0 -I{} rm {} &> /dev/null
    

    【讨论】:

      【解决方案2】:

      如果你可以假设 GNU find,那么你可以使用find . -name '*.pyc' -delete

      或者,find . -name '*.pyc' -exec rm -rf {} '+'

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-03
        • 2015-01-21
        • 2012-03-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多