【问题标题】:Deleting files older than 10 days in wildcard directory loop在通配符目录循环中删除超过 10 天的文件
【发布时间】:2015-07-02 02:45:55
【问题描述】:

我想从多个目录中删除旧文件,但其中一个路径属性有一个通配符。所以我试图遍历每个目录而不指定每个目录。我想我快到了,但我不确定如何 cd 进入特定目录以删除相关文件。

#! /bin/bash

DELETE_SEARCH_DIR=/apps/super/userprojects/elasticsearch/v131/node*/elasticsearch-1.3.1/logs/

    for entry in `ls $DELETE_SEARCH_DIR`; do
      find $path -name "*super*"  -type f -mtime +10 -print -delete
      #find . -type f -name $entry -exec rm -f {} \;
    done

关于如何进入特定目录并应用删除的任何想法?

【问题讨论】:

标签: bash shell unix


【解决方案1】:

find可以在多个目录中搜索。你可以这样做:

DELETE_SEARCH_DIR=/apps/super/userprojects/elasticsearch/v131/node*/elasticsearch-1.3.1/logs
find $DELETE_SEARCH_DIR -type f -name '*super*' -mtime +10 -print -delete

【讨论】:

  • 找到进入子目录
猜你喜欢
  • 2017-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-06
相关资源
最近更新 更多