The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 01-02-2009
Hangman2 Hangman2 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 27
That worked

This Worked.

file_name=`ls -ltr /dir1/dir2 | grep '^-' | tail -1 | awk '{print $9}' `


>>
I wouldn't use four external commands just the get a filename
>>

Is there an alternate to just get the latest file name from a dir?

I used grep to just get files from a dir or skip the dirs underneath it, tail -1 gives the latest file name. Awk just prints the name.

Thanks.