Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-04-2008, 01:21 AM   #1
LQ Newbie
Registered: Jul 2008
Posts: 8

Rep: Reputation: Disabled
newest data file

DEar Friends

I am trying to write a bash script.

Forexample there are 5 files; named as :

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
Old 07-04-2008, 01:42 AM   #2
Mr. C.
Senior Member
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 62
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find newest file capella Linux - Software 9 04-28-2012 04:26 AM
LXer: Migrating to the Newest Linux File System ext4 LXer Syndicated Linux News 0 05-07-2008 02:40 AM
gnuplot, pull X data from file, specify Y data at cmd line? hedpe Programming 5 03-15-2007 11:32 PM
list directory only show newest file amarok* carl0ski Linux - General 1 01-29-2006 09:31 AM
Copying the newest file in a directory to another location Transition Linux - General 2 01-14-2005 11:53 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:46 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration