此命令使用-printf '%Tc %p\n'
给出上次修改的文件的日期。
$ find ./ -daystart -mtime -3 -type f ! -mtime -1 -printf '%Tc %p\n'
Tue 08 Mar 2016 12:25:01 NZDT ./compareKPIs-log
Tue 08 Mar 2016 18:04:58 NZDT ./backup_public_html_20160308.tgz
Tue 08 Mar 2016 18:04:58 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
我想要做的是将日期格式控制为YYYY-mm-dd
。我该怎么做呢? (hh:mm:如果需要,也可以添加ss)
例如-printf '%TY %p\n'
会给我一年%TY
:
$ find ./ -daystart -mtime -3 -type f ! -mtime -1 -printf '%TY %p\n'
2016 ./compareKPIs-log
2016 ./backup_public_html_20160308.tgz
2016 ./log-file
2016 ./compareKPIs-error
2016 ./backup_public_html_20160307.tgz
例如-printf '%Tm %p\n'
会给我一个月%Tm
:
$ find ./ -daystart -mtime -3 -type f ! -mtime -1 -printf '%Tm %p\n'
03 ./compareKPIs-log
03 ./backup_public_html_20160308.tgz
03 ./log-file
03 ./compareKPIs-error
03 ./backup_public_html_20160307.tgz
另一个optio n是ls
-exec ls -ld {} \;
,但我不确定这是否可行。
$ find ./ -daystart -mtime -3 -type f ! -mtime -1 -exec ls -ld {} \;
-rw-rw-r-- 1 kevinsmith kevinsmith 254160 Mar 8 12:25 ./compareKPIs-log
-rw-rw-r-- 1 kevinsmith kevinsmith 956411793 Mar 8 18:04 ./backup_public_html_20160308.tgz
-rw-rw-r-- 1 kevinsmith kevinsmith 78577523 Mar 8 18:04 ./log-file
-rw-rw-r-- 1 kevinsmith kevinsmith 46080 Mar 8 12:25 ./compareKPIs-error
-rw-rw-r-- 1 kevinsmith kevinsmith 956407500 Mar 7 18:05 ./backup_public_html_20160307.tgz
答案 0 :(得分:3)
您可以在-printf
的{{1}}参数中使用多个%T k,例如:
find
YYYY-mm-dd [file] 格式'%TY-%Tm-%Td %p\n'
YYYY-mm-dd hh:mm:ss [file] format '%TY-%Tm-%Td %TH:%TM:%.2TS %p\n'
YYYY-mm-dd hh:mm:ss.ssssssssss [file] format