Mass-Rename Files Using an Easy CLI Method
You may find this useful to rename MP3 or image files in a directory, so they will all look the same. The following script will work on directories with less than 100 files of the same type, and will rename all of them to file01, file02, file03, ... and so on.
|
|
You may find this useful to rename MP3 or image files in a directory, so they will all look the same.
The following script will work on directories with less than 100 files of the same type, and will rename all of them to file01, file02, file03, ... and so on.
j=1;
for i in *; do
if [[ $j -lt 10 ]]; then
mv "${i}" "file0${j}";
fi;
if [[ $j -ge 10 && $j -lt 100 ]]; then
mv "${i}" "file${j}";
fi;
j=$(($j+1));
done
You can only use it for certain types of files in a directory, like this:
j=1;
for i in *.ogg; do
if [[ $j -lt 10 ]]; then
mv "${i}" "audio0${j}.ogg";
fi;
if [[ $j -ge 10 && $j -lt 100 ]]; then
mv "${i}" "audio${j}.ogg";
fi;
j=$(($j+1));
done
This will rename all the Ogg files in a directory to audio01.ogg, audio02.ogg, audio03.ogg, and so on. You can test it for whatever files you like, however make a back-up first, since you can accidentally rename files or even directories which you don't want renamed.
Full Story |
This topic does not have any threads posted yet!
You cannot post until you login.