Renaming Files

IFS=$(echo -en "\n\b")
for X in `ls *`; do mv "$X" "$(echo $X | sed 's/^[ \t]*//;s/[ \t]*$//')"; done


# Renaming a directory of 'title01.mkv' files
for X in `ls *.mkv`;do Y=`echo $X | sed 's/title\(..\)\.mkv/\1/'`;Z=`printf "%02d\n" $((10#$Y + 1 ))`;echo mv "$X" "Scrubs - s05e$Z - .mkv"; done


https://stackoverflow.com/questions/12821715/convert-string-into-integer-in-bash-script/12821845#12821845
https://stackoverflow.com/questions/8789729/how-to-zero-pad-a-sequence-of-integers-in-bash-so-that-all-have-the-same-width
Comments