-   Linux - General (
-   -   Quickly find the newest file in a directory (

yorkshiresteve 02-15-2009 07: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:

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

ilikejam 02-15-2009 11:25 AM


'ls -tr | tail -n 1'


yorkshiresteve 02-15-2009 11:32 AM

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

All times are GMT -5. The time now is 01:50 AM.