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 -->
  #6 (permalink)  
Old 01-02-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by Hangman2 View Post
Is there an alternate to just get the latest file name from a dir?

Code:
dir=/dir1/dir2  ## adjust to taste
file_name=$(
 ls -t "$dir" |
 while IFS= read -r file
 do
   [ -f "$dir/$file" ] && { printf "%s\n" "$file"; break; }
 done
)