LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 07-04-2008, 02:21 AM   #1
wolfindark
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 :
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
 
Old 07-04-2008, 02:42 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

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


Reply


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 05:26 AM
LXer: Migrating to the Newest Linux File System ext4 LXer Syndicated Linux News 0 05-07-2008 03:40 AM
gnuplot, pull X data from file, specify Y data at cmd line? hedpe Programming 5 03-16-2007 12:32 AM
list directory only show newest file amarok* carl0ski Linux - General 1 01-29-2006 10:31 AM
Copying the newest file in a directory to another location Transition Linux - General 2 01-14-2005 12:53 PM


All times are GMT -5. The time now is 10:58 PM.

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