Find command modified date in output

I'm using the find command find /path/on/server -mtime -1 -name '*.js' to get a list of files modified recently but I'd like the output to also have the date the files were modified


Solution 1:

You can use the -printf option to find to print this if you want

find find /path/on/server -mtime -1 -name '*.js' -printf "%h%f %TD\n"
  • %h the leading directories
  • %f the file name
  • %TD the files modification date

the %p format specifier can be used in place of %h%f for the full path.

You get output like

/path/on/server/somefile.ext 05/24/12

There are lots of options to the printf option so you can build any output format you want.

Solution 2:

You can customise stat to print exactly the information you like:

find /path/on/server -mtime -1 -name '*.js' -exec stat -c "%n: %y" {} \;

The way this works is that find calls stat -c "%n: %y" FILE; for every FILE that it finds in it's search, and stat prints that to your terminal.

This results in something like:

somefile.txt: 2012-06-13 02:11:59.208822237 +0100