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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search for latest file in dir and put name in to variable

Status
Not open for further replies.

Scunningham99

Programmer
Sep 20, 2001
815
GB
Hi all

I would like to search a dir for a file and put the name in to a variable. so i can the do conditions on the name of file. anyone have any clues!

regards

S
 
Hi Scunningham99,

if I understand your question and if your directory only contains regular files, then the following would do the job:

LATEST_FILE=`ls -rt your_search_dir | tail -1`

The variable LATEST_FILE contains the newest file in that directory.

Hope that helps

mrjazz [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top