Um in einem Pfad alle Ordner- und Datei-Namen rekursiv umzubenennen, braucht es folgendes Script:
#!/bin/bash
[ "`whoami`" = root ] || exec sudo "$0" "$@"
echo -en "\n BEWARE! Starting from current directory (`pwd`),"
echo -en " files and directories with spaces in name will be renamed automatically.\n"
echo -en "\n Press \"ENTER\" to continue or \"N\" to exit:"
read ops
case "$ops" in
n|N)
echo -en "\n Canceled by User. Exiting...\n"
exit 1 ;;
*)
echo -en "\n Starting...\n" ;;
esac
number=0 # Number of renamed.
number_not=0 # Number of not renamed.
IFS=$'\n'
array=( `find ./ -type d` ) # Find catalogs recursively.
for (( i = ${#array[@]}; i; )); do
pushd "${array[--i]}" >/dev/null 2>&1
for name in *
do
echo "$name" | grep -q " "
if [ $? -eq 0 ]
then
newname=`echo $name | sed -e "s/ /_/g"`
if [ -e $newname ]
then
let "number_not +=1"
echo " Not renaming: $name"
else
let "number += 1"
echo "$number Renaming: $name"
mv "$name" "$newname"
fi
fi
done
popd >/dev/null 2>&1
done
echo -en "\n All operations are ready."
if [ "$number_not" -ne "0" ]
then echo -en "\n $number_not not renamed."
fi
if [ "$number" -eq "0" ]
then echo -en "\n Nothing been renamed.\n"
elif [ "$number" -eq "1" ]
then echo -en "\n $number renamed.\n"
else echo -en "\n Renamed files and catalogs: $number\n"
fi
exit 0
Vorsicht! Es werden ALLE Ordner und Dateien umbenannt ab dem Pfad, in dem Ihr Euch befindet.
Viel Spass beim Ausprobieren
Schreibe einen Kommentar