LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   newest data file (https://www.linuxquestions.org/questions/linux-newbie-8/newest-data-file-653491/)

wolfindark 07-04-2008 02:21 AM

newest data file
 
DEar Friends

I am trying to write a bash script.

Forexample there are 5 files; named as :
test-res-0001.dat.gz
test-res-0002.dat.gz
test-res-0003.dat.gz
test-res-0004.dat.gz
test-res-0005.dat.gz

I want to get newest file name test-res-0005.dat.gz in my script. This file is the most recently created one.
I want to assign this file name as RES_DATA="test-res-????.dat.gz". I do not know how can I get the name of recently created data file.

Any help will be appreciated.
thank you

Mr. C. 07-04-2008 02:42 AM

ls -l # gives you a long listing
ls -lt # gives you a long listing sorted by modified time, newest first
ls -ltr # gives you a long listing sorted by modified time, oldest first

Remove the "l" (ell) for short output. Add -1 (one) to get a single column.

Pipe to head -1 or tail -1 as necessary

ls -t1 | head -1

gives you the newest file.


All times are GMT -5. The time now is 01:56 AM.