Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 02-15-2009, 07:54 AM   #1
LQ Newbie
Registered: Jul 2003
Location: West Yorkshire, England
Distribution: Redhat 7.2
Posts: 21

Rep: Reputation: 15
Quickly find the newest file in a directory

Hi All,

Just a quick one... I need a quick command which will just give me the filename of the most-recently-modified file in a directory.

All I need to do is backup the data in my database in to a file with the current data/time in the name, then reload it.

Here's what I've got so far:
mysqldump -t -c -u username -p database > data/backups/`date +%Y%m%d-%H%M%S`.sql
All I need now is this bit:
mysql -u username -p database < data/backups/`latest_file`.sql
Old 02-15-2009, 11:25 AM   #2
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96

'ls -tr | tail -n 1'

Old 02-15-2009, 11:32 AM   #3
LQ Newbie
Registered: Jul 2003
Location: West Yorkshire, England
Distribution: Redhat 7.2
Posts: 21

Original Poster
Rep: Reputation: 15
Dave, that's spot on - thank you very much!


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 On
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
find newest files in a directory macushk Linux - Newbie 3 05-05-2008 04:16 AM
list directory only show newest file amarok* carl0ski Linux - General 1 01-29-2006 09:31 AM
how to get back quickly to directory with long path name learnfast Linux - Newbie 1 05-20-2005 05:26 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 - General

All times are GMT -5. The time now is 04:03 PM.

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