Created
November 18, 2011 23:57
-
-
Save skhatri/1378146 to your computer and use it in GitHub Desktop.
bulk rename files in directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # | |
| # Usage: ./bulkrename.sh /backup/project dump data_backup_ | |
| # | |
| # the files matching the pattern | |
| # YYYdumpXXXX will be converted to | |
| # YYYdata_backup_XXXX | |
| # | |
| # | |
| targetdir=$1 || "." | |
| from=$2||'junk' | |
| to=$3||'junk' | |
| for file in `ls $targetdir` | |
| do | |
| newname=`echo $file|sed s/$from/$to/g` | |
| echo "renaming from $file to $newname" | |
| mv $targetdir/$file $targetdir/$newname | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment