列出过去 x 天(不包括今天)已修改的文件



这列出了在最后一天(24 小时)修改的文件,-mtime -1 ,其名称中包含字符串"UGW"-name '*UGW*'

find ./ -mtime -1 -type f -name '*UGW*' -printf '%Tc %pn' | sort

有没有一种简单的方法可以修改它,以便我只列出最后 X 天但排除今天?

注意:我在这里排序,但我认为这不是按时间戳 100% 正确排序。

EDIT1 基于下面的 anser 得到以下错误

:~/tmp$ find ./ -mtime -1 -type f -name '*' -printf '%Tc %pn'                                                                    Tue 08 Mar 2016 12:25:01 NZDT ./compareKPIs-log
    Mon 07 Mar 2016 18:05:02 NZDT ./log-file
    Tue 08 Mar 2016 12:25:01 NZDT ./compareKPIs-error
    Mon 07 Mar 2016 18:05:02 NZDT ./backup_public_html_20160307.tgz

:~/tmp$ comm -13 <(find ./ -daystart -mtime -1 -type f   -printf '%Tc %pn' ) <(find ./ -daystart -mtime -3 -type f   -printf '%Tc %pn' )
    Sun 06 Mar 2016 18:05:00 NZDT ./backup_public_html_20160306.tgz
    comm: file 2 is not in sorted order
    Mon 07 Mar 2016 18:05:02 NZDT ./log-file
    comm: file 1 is not in sorted order
    Mon 07 Mar 2016 18:05:02 NZDT ./backup_public_html_20160307.tgz

***编辑:执行此操作的实际方法:

find ./ -daystart -mtime -3 -type f  ! -mtime -1  -printf '%Tc %pn'

使用:

  • 今天要排除! -mtime -1
  • -daystart 00:00开始

真的很黑客,但是呢

comm -13 <(find ./ -daystart -mtime -1 -type f   -printf '%Tc %pn' | sort) <(find ./ -daystart -mtime -3 -type f   -printf '%Tc %pn' | sort)

comm的命令行选项包括:

-1 suppress column 1 (lines unique to FILE1)
-2 suppress column 2 (lines unique to FILE2)
-3 suppress column 3 (lines that appear in both files)

最新更新