I have a directory with daily backups of my entire MySQL database.
I want to import the most recent backup into the database.

I know to import a backup I need to use mysql -u root -ppasswordhere < backup.sql

I've managed to get the most recent file with ls -Art | grep '.sql' | tail -n 1, but I don't really know how to pipe the output to the command mysql -u root -ppasswordhere

I am sure the answer is really obvious, I'm just confused.


Have you tried this?

mysql -u root -ppasswordhere < $(ls -Art | grep '.sql' | tail -n 1)
  • 1
    you are welcome. if you want to accept the answer then please click on the according tick button. like shown here: i.stack.imgur.com/uqJeW.png – replay Dec 31 '13 at 13:56
  • 2
    I know, I know. I was waiting for the time limit. I cannot accept the answer in the first... (I guess) 15 minutes. – Ivan Dokov Dec 31 '13 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.