Skip to content

Instantly share code, notes, and snippets.

@crespoxiao
Last active September 7, 2016 03:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crespoxiao/3d033f71e9a94ce7b5a9bb48ca29dc34 to your computer and use it in GitHub Desktop.
Save crespoxiao/3d033f71e9a94ce7b5a9bb48ca29dc34 to your computer and use it in GitHub Desktop.
example shell for batch rename files (change the first 4 char of file name to DRC)
#!/bin/bash
currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
echo "current path is:"$currentDir;
list_alldir(){
for file2 in `ls -a $1`
do
if [ x"$file2" != x"." -a x"$file2" != x".." ];then
if [ -d "$1/$file2" ];then
echo "$1/$file2"
# do not rename files in Categories folder
if [ "$file2" != "Categories" ];then
cd "$1/$file2"
for var in `ls`; do
if test -f $var
then
sudo mv -f "$var" `echo "$var" |sed 's/^..../DRC/'`;
echo $var edit succeed
fi
done
cd $currentDir
fi
list_alldir "$1/$file2"
fi
fi
done
}
list_alldir ./
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment