Skip to content

Instantly share code, notes, and snippets.

@skhatri
Created November 18, 2011 23:57
Show Gist options
  • Select an option

  • Save skhatri/1378146 to your computer and use it in GitHub Desktop.

Select an option

Save skhatri/1378146 to your computer and use it in GitHub Desktop.
bulk rename files in directory
#!/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