Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
google site



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-12-2010
Registered User
 

Join Date: Oct 2009
Location: Beijing, China
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
How to get the latest modified file name in /home directory?

I only know how to list all sub-directories or files in specified directory. I don't know how to order them by modified date, furthermore, I don't know how to get the top one file in the sorted list. Wish you can do me a favor. Thanks in advance!
Sponsored Links
  #2  
Old 03-12-2010
karthigayan's Avatar
Registered User
 

Join Date: Apr 2009
Location: /usr/bin
Posts: 116
Thanks: 0
Thanked 2 Times in 2 Posts
In ls there in a option called -t .It will list based on the modified time .


Code:
ls -lrt

To get the recently modified file use the following,


Code:
ls -lrt | tail -n 2

  #3  
Old 03-12-2010
amitranjansahu's Avatar
Registered User
 

Join Date: Jan 2009
Location: Bangalore,INDIA
Posts: 456
Thanks: 2
Thanked 14 Times in 14 Posts
Check the man pages of ls and head.

ls -lrt

ls -lrt | head -1
  #4  
Old 03-12-2010
Registered User
 

Join Date: Oct 2009
Location: Beijing, China
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you both! My problem is solved with your solutions.
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to open a last modified file in a directory apsprabhu UNIX for Advanced & Expert Users 5 02-24-2010 12:20 AM
How to find the latest modified file from the unix server. sreenu80 Shell Programming and Scripting 2 10-16-2009 05:40 AM
Copy the latest file to a directory spkandy Shell Programming and Scripting 2 08-10-2009 04:16 AM
Copy the latest file from one directory to another chandancsc Shell Programming and Scripting 3 08-07-2009 04:35 AM
How to zip a modified file 15 days before but not scanning my sub directory files skrish70 Shell Programming and Scripting 1 10-10-2005 03:41 PM



All times are GMT -4. The time now is 08:00 AM.