Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 have a shell script that executes a backup program and saves the output in a folder. I would like to update the name of the output folder every time the shell script run. In the end I want to have many files with different names like this:

innobackupex --user=root --password=@g@1n --database="open_cart" /var/backup/backup_1 --no-timestamp

And after running the shell script again:

innobackupex --user=root --password=@g@1n --database="open_cart" /var/backup/backup_2 --no-timestamp
share|improve this question
use backup_ instead and check for existence of files starting at 1. when you get to one that doesn't exist, use that... – RobotHumans Aug 28 '12 at 14:12
Cool but why so difficult? Why not use a standard time stamp? Use $(date +"%m-%d-%Y") and you do not need to worry about iteration – Rinzwind Aug 28 '12 at 14:13
@Rinzwind i think this will be much better as i will have different folders each time thanks alot – Sitati Aug 28 '12 at 20:37
Sorry but a timestamp makes it a different folder and you get to see when it was made ;) @Sitati – Rinzwind Aug 28 '12 at 21:34
up vote 1 down vote accepted

You need to store the incremental value somewhere, for example in a log file

(( NUM++ ))
share|improve this answer
I have also tried this and it works fine – Sitati Aug 28 '12 at 20:38
if it suites your needs please upvote the answer (and accept it if is also acceptable ;) ) @Sitati thanks in advance – Rinzwind Aug 28 '12 at 21:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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