LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Quickly find the newest file in a directory (http://www.linuxquestions.org/questions/linux-general-1/quickly-find-the-newest-file-in-a-directory-704806/)

yorkshiresteve 02-15-2009 08:54 AM

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:
Code:

mysqldump -t -c -u username -p database > data/backups/`date +%Y%m%d-%H%M%S`.sql
All I need now is this bit:
Code:

mysql -u username -p database < data/backups/`latest_file`.sql
Thanks!

ilikejam 02-15-2009 12:25 PM

Hi.

'ls -tr | tail -n 1'

Dave

yorkshiresteve 02-15-2009 12:32 PM

Dave, that's spot on - thank you very much!


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