【问题标题】:How to show deleted file when using command `find . -name sample.txt -delete`使用命令 `find 时如何显示已删除的文件。 -name sample.txt -delete`
【发布时间】:2020-03-25 14:10:25
【问题描述】:

我需要像rm -v sample.txt 这样的输出。 命令find有“-v”之类的选项吗?

【问题讨论】:

    标签: find verbose


    【解决方案1】:

    使用 FreeBSD 和 find 的 Busybox 实现测试:

    $ find . -name sample.txt  -delete -exec echo removed "'{}'" \; | sed "s,^removed '\./,removed ',"
    removed 'sample.txt'
    

    使用 GNU find 你也可以使用-printf:

    $ find . -name sample.txt -printf "removed '%f'\n" -delete
    removed 'sample.txt'
    

    【讨论】:

      【解决方案2】:

      简单愚蠢的解决方案:

      find . -name sample.txt && find . -name sample.txt -delete
      

      【讨论】:

        猜你喜欢
        • 2021-06-07
        • 1970-01-01
        • 1970-01-01
        • 2018-12-28
        • 2014-09-19
        • 1970-01-01
        • 2021-12-25
        • 1970-01-01
        • 2018-07-17
        相关资源
        最近更新 更多