Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the last modifed file of a ls output.

Status
Not open for further replies.

warpedFrenzy

Technical User
Aug 21, 2010
3
0
0
AU

I have to find the last modified file on a given date in the cwd.

So far I know (with a random example of date here)
Code:
ls -ltr | grep '2010-08-20'
gives me the list of files in the cwd on that date.

I then need to find the last modified file of this list.

I know
Code:
find . -newer filename
gives you any files newer/modified after filename in the cwd.

But how do I find the last modified file on a specified date?

Thankyou for any help you can provide.
 
I just found ls -t gives sort by time stamp (latest first).
But I havent been able to put them together.
Then single out the last modified file, in order to compare it to another filename.
 
Try:

Code:
ls -lt | awk -v DATE=2010-08-20 '$6 == DATE {print $NF;exit}'

This assumes that the filenames do not contain spaces (or dates!).

Annihilannic.
 
Thanks a BILLION Annihlannic!
You've been the most helpful person I've encountered on a forum yet!.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top