【问题标题】:find files or directories that are 30 or more days old, recursively, BUT starting the search from specific directory递归查找 30 天或更长时间的文件或目录,但从特定目录开始搜索
【发布时间】:2016-02-02 18:57:06
【问题描述】:

我一直在搜索,但我找不到在 Linux 的 1 行中基本上执行以下操作的方法,以便找到超过 30 天的文件和目录,从 script_dir 开始递归搜索:

cd $script_dir
find . -type f -or -type d -mtime +30

如果我不使用 cd 切换到我需要开始递归搜索的目录(并且直接使用 find),那么,虽然我在 find 处指定了 script_dir,但递归搜索从我当前所在的目录开始而不是来自 script_dir 和此目录下。我想做类似以下的事情,即使我目前在 script_dir 以外的其他目录,递归搜索也从 script_dir 开始:

find $script_dir -type f -or -type d -mtime +30

谢谢。

【问题讨论】:

  • find "$script_dir" -type f -or -type d -mtime +30 不做你想做的事吗?它应该。祝你好运。
  • 不,它没有。它的工作原理与 find 相同。 -type f -or -type d -mtime +30,在您当前所在的目录中,因此忽略 $script_dir。
  • doah,我认为我们需要像find "$script_dir" \( -type f -or -type d \) -mtime +30 一样保护-or(逃脱的() 对)。 find 中的谓词与默认的-and 连接,但-or 需要“保护”以防止过早评估。 IHTH 祝你好运。

标签: linux find


【解决方案1】:

在一行中,您可以这样做:

cd /path/to/directory && find . -type f -or -type d -mtime +30

从指定目录进行搜索

【讨论】:

    猜你喜欢
    • 2013-10-21
    • 1970-01-01
    • 2012-04-07
    • 2015-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    相关资源
    最近更新 更多