【问题标题】:Using find to delete all files (without sub dir)使用 find 删除所有文件(没有子目录)
【发布时间】:2012-07-30 12:14:23
【问题描述】:

这是我的目录的结构:

./archive
    /sub1
        - file1
        - file2
    /sub2
        - file3
        - file4

我尝试使用此命令查找所有超过 6 个月的文件以将其删除:

find ./archive -mindepth 1 -mtime +180 -delete

所有文件和子目录都被删除了,我只想要删除的file1, file2, file3, file4,不包括sub1sub2,请指教。

【问题讨论】:

    标签: bash shell unix


    【解决方案1】:

    find 支持-type 选项。使用它来指定以f 作为参数的常规文件。

    find ./archive -mindepth 1 -mtime +180 -delete -type f
    

    【讨论】:

      【解决方案2】:

      包含一个 -type f 标志,将查找限制为仅文件:

      find ./archive -mindepth 1 -mtime +180 -delete -type f
      

      【讨论】:

        【解决方案3】:

        添加-type f 选项以排除目录:

        find ./archive -mindepth 1 -mtime +180 -type f -delete 
        

        【讨论】:

          猜你喜欢
          • 2011-08-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-01-07
          • 1970-01-01
          • 2011-08-05
          • 2010-11-12
          • 1970-01-01
          相关资源
          最近更新 更多