Last active
September 7, 2016 03:34
-
-
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)
This file contains 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/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