0

I have a requirement to identify the list of files ( from past 7 days) having particular pattern - say from large number of archive files and print the filenames according to their file modified timestamp.

Any thoughts?

find /Source -name "TEST\_\*" -mtime -7 -print0| xargs -0 grep -l "pattern"

Got the filenames - need it to be sorted by its file modified timestamp.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
ganesh B
  • 3
  • 1

1 Answers1

0

you should use stat -c %Y or stat -c %y

the whole statement could look like:

find /Source -name "TEST\_\*" -mtime -7 -print0| xargs -0 -i  sh -c 'echo "$(stat -c %y "{}") {}"' | sort -rn

or

find /Source -name "TEST\_\*" -mtime -7 -print0| xargs -0 -i  sh -c 'echo "$(stat -c %Y "{}") {}"' | sort -rn

help for xargs i found here: Running multiple commands with xargs

from man stat :

  %y   time of last data modification, human-readable
  %Y   time of last data modification, seconds since Epoch
Oliver Gaida
  • 1,722
  • 7
  • 14