Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Latest File in the Directory

Status
Not open for further replies.

Milleniumlegend

IS-IT--Management
Dec 16, 2003
135
0
0
I am trying to find a latest zip file in a directory so that I can unzip them and transfer them across to another directory.

I have under src/XYZ001_28_10_2004_BIN.ZIP and src/XYZ001_27_10_2004_BIN.ZIP and
src/XYZ001_10_09_2004_BIN.ZIP

etc and I would like to pick the latest one which is
src/XYZ001_28_10_2004_BIN.ZIP



Many Thanks in advance.
 
Hi,
The following command will give you the latest file in the current directory:

ls -tr | tail -1

Regards
 
You may try something like this:
lastzip=$(ls -t src/XYZ001_*_BIN.ZIP | head -1)
echo $lastzip

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top