2

this command uses -printf '%Tc %p\n' to give the date the files where last modified.

$ 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

what I want to do is control the date format to be YYYY-mm-dd. How do I do this? (hh:mm:ss can be added here also if necessary)

for instance -printf '%TY %p\n' will give me the year%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

for instance -printf '%Tm %p\n' will give me the month%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

Another option is to ls -exec ls -ld {} \; but I am not sure if it is possible this way.

$ 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
HattrickNZ
  • 4,373
  • 15
  • 54
  • 98
  • See similar question for more answers: https://stackoverflow.com/questions/20893022/how-to-display-modified-date-time-with-find-command – wisbucky Mar 07 '19 at 23:27

1 Answers1

10

You can use more than one %Tk in -printf argument of find, eg:

  • '%TY-%Tm-%Td %p\n' for YYYY-mm-dd [file] format
  • '%TY-%Tm-%Td %TH:%TM:%.2TS %p\n' for YYYY-mm-dd hh:mm:ss [file] format
  • '%TY-%Tm-%Td %TH:%TM:%TS %p\n' for YYYY-mm-dd hh:mm:ss.ssssssssss [file] format
coolparadox
  • 508
  • 3
  • 10