How to find the latest file in a directoryThere are multiple ways you can find the latest file in a directory. Using a combination of "ls" and "awk" is the easiest one. $cd DIRECTORY_NAME $ls -ltr *.* | awk '{ f=$NF }; END{ print f }' The "ls -ltr" command lists the files in the directory ordered by their time stamp. You can look for specific file names/extensions by replacing *.* with whatever pattern you want to look for. For example: ls -ltr *.txt will list only files having .txt extension. awk command above will pick the last listed file i.e. the latest file and print its name. You can store the name of the file as below: latest_file=`ls -ltr *.* | awk '{ f=$NF }; END{ print f }'` echo $latest_file
By: Java
1573 days ago
![]() Photos
No photo uploaded for this blog.
Featured Blogs![]() |