rename

As you know, the mv command renames files. For example:

mv oldname newname

However, what if you don't know the filenames yet? The rename command comes in really handy here.

rename .log .log.‘date +%F-%H:%M:%S‘ *

replaces all files with the extension .log with .log.<dateformat>.

#!/bin/sh
backup_dir='/root/mysql_backups/'
find "$backup_dir" -type f -ctime +7 -exec rm {} \;
cd "$backup_dir"
rename .sql.6 .sql.7 *
rename .sql.5 .sql.6 *
rename .sql.4 .sql.5 *
rename .sql.3 .sql.4 *
rename .sql.2 .sql.3 *
rename .sql.1 .sql.2 *
#rename .sql .sql.1 *.sql
find "$backup_dir" -type f -name '*.sql' -exec mv {} {}.1 \;
mysqldump -u root -h 172.16.203.53 clinicalcafe  --compress --routines -r "$backup_dir"clinicalcafe.sql
mysqldump -u root -h 172.16.203.53 mysql  --compress --routines -r "$backup_dir"mysql.172.16.203.53.sql

http://www.cyberciti.biz/tips/renaming-multiple-files-at-a-shell-prompt.html

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License