linux - prepend date to a filename in a shell script -
I have the following shell script and want to rename the file db_backup.sql
so that the change The current date is prepared for it, eg yyyy-mm-dd-db_backup.sql
#! / Bin / sh mysqldump ... / _sql / db_backup.sql gzip -f_sql / db_backup.sql
Simple question, hopefully quick and simple answer!
You can use the date
command to do what you want Can:
#! / Bin / sh fspec = / _ sql / $ (date +% y-% m-% D) -db_backup.sql mysqldump ... $ {fspec} gzip -f $ {FSPC}
If you are using a shell that does not support $ ()
, instead you may need to use backcatics:
< Code> fspec = / _ sql / `date +% y-% m-% d`-db_backup.sql
Comments
Post a Comment