LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 01: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, 01:42 AM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:39 AM.

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
Open Source Consulting | Domain Registration