如何按日期范围列出文件?

Val*_*lva 4 linux bash command-line find

我想列出 3 天前的文件。我在stackoverflow找到了这个:

find . -type f -printf "%-.22T+ %M %n %-8u %-8g %8s %Tx %.8TX %p\n" | sort | cut -f 2- -d ' ' | grep 2012
Run Code Online (Sandbox Code Playgroud)

但我有点不明白整个命令是什么意思。我想知道是否有一些简短易懂的东西。

Red*_*ick 6

这应该工作

find . -type f -mtime -3
Run Code Online (Sandbox Code Playgroud)

解释

find         find files
.            starting in the current directory (and it's subdirectories)
-type f      which are plain files (not directories, or devices etc)
-mtime -3    modified less than 3 days ago
Run Code Online (Sandbox Code Playgroud)

man find详细信息


更新

要查找在特定日期和时间(例如 2013 年 2 月 20 日 08:15)之前最后修改的文件,您可以执行以下操作

  touch -t 201302200815 freds_accident
  find . -type f ! -newer freds_accident
  rm freds_accident
Run Code Online (Sandbox Code Playgroud)

看到man touch (或info touch- 呃!)

这有点可怕,可能有更好的方法。上述方法适用于古老的和非 GNU Unix 以及当前的 Linux。