【问题标题】:Remove all backup files in Linux using Shell script recursively [duplicate]使用Shell脚本递归删除Linux中的所有备份文件[重复]
【发布时间】:2012-12-20 15:41:02
【问题描述】:

如何在 Ubuntu 的特定文件夹中递归删除所有备份文件,即以 ~ 结尾的文件?

任何编程语言的脚本都可以。

【问题讨论】:

标签: linux bash shell ubuntu


【解决方案1】:

首先,递归是什么意思?递归是实现圆顶算法的一种便捷方式,但往往被过度使用——但有些人也将该术语应用于搜索目录树(可以通过递归的其他方式实现)。如果您只是想删除与目录树中特定 glob 匹配的所有文件,那么......

find /base/directory/ -type f -iname '*~' -exec rm -f {}\;

(但您可能想先尝试find /base/directory/ -type f -iname '*~' -exec ls -l {}\;)。

【讨论】:

    【解决方案2】:

    一种方式:

    find folder -name '*~' -print0 | xargs -0 rm -f
    

    基本上看“man find”

    【讨论】:

      【解决方案3】:

      首先,您可以使用简单的find 命令:

      find . -type f -name '*~' -delete
      

      【讨论】:

        猜你喜欢
        • 2016-07-27
        • 2017-10-05
        • 1970-01-01
        • 1970-01-01
        • 2011-09-25
        • 1970-01-01
        • 2023-04-10
        • 1970-01-01
        • 2013-12-18
        相关资源
        最近更新 更多