Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am getting the databases from mysql and my database name is username_something. I am getting the username and then puting the respective backups in corresponding folders like

tar bala bla  /backups/sql/username/username_something.tar.sql.gz

The problem is system worrks if i have the folder username already there but for new databases if get the error like unknown file path.

How can i do that if username folder is not there it should be created

share|improve this question

migrated from stackoverflow.com Nov 8 '10 at 11:22

This question came from our site for professional and enthusiast programmers.

up vote 2 down vote accepted

You can use mkdir before the tar command to create the directory. If multiple dirs in the path may be missing, you can use the -p flag. Using -p will also suppress the error if the directory already exists.

share|improve this answer
mkdir -p /backups/sql/username && tar ...
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .