The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 05-29-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555
Quote:
Originally Posted by lorcan
Aigles, Just a small correction in your code,
to get the latest file we have to sort based on the time,

so the 4th line should have been like


Code:
last_file=$(ls -t1 $filename.$datestamp.* 2>/dev/null | tail -1)

normally if used with tail -1, we would want ls -1tr instead. however for this particular case,i think because the filenames are already timestamped , with a number at the back, when doing ls -1, its still "sorted" to latest file.