//View Tip #882
Similar Tips
» Rename many files using find and perl
» swap files
» Bash efficiency formula ;-)
» Find files by mime-type
» Generate a random password

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
To find the last modified files in a directory you can use ls -ltr. To find the last modified file on a file system it will not work, but the following command will work:

find /etc -type f -printf "%T@ %T+ %p" | sort -n


View Comments »




Comments 

Add your comment

Comments are currently disabled
Nice one.  I had to add a \n after the %p, though.
Posted 2009-09-15 11:01:36
Yes, I also had to add '\n'.  I also piped through 'sort -rn|head' to limit the output.  It's also possible to speed things up by using the test '-cnewer' in 'find'.  Just picking any file in the directory your searching.  If you don't get any output you've managed to pick the most recent modified file.
Posted 2009-09-16 00:30:55
sudo find /etc -type f -printf "%T@ %T+ %p \n" | sort -n | less
Posted 2009-09-20 06:51:15
MacThunder
Why so complicated?
I am used to:

find . -type f -mtime 0
Posted 2010-06-10 02:31:34

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit