Skip to content

Instantly share code, notes, and snippets.

@imzjy
Last active December 29, 2015 07:39
Show Gist options
  • Save imzjy/7637464 to your computer and use it in GitHub Desktop.
Save imzjy/7637464 to your computer and use it in GitHub Desktop.
rename MP3 files, and remove first 4 characters.
#!/bin/sh
if [[ ! -d $1 ]]; then
echo "please specific a MP3 directory"
exit;
fi
SAVEIFS=$IFS
IFS=$( echo -en "\n\b" ) #fix mp3 files contain a space
for file in $( find $1 -name *.mp3 ); do
echo $file
MP3NAME=$( basename $file)
PATHNAME=$( dirname $file )
mv $PATHNAME/$MP3NAME $PATHNAME/$( echo $MP3NAME | cut -c 5- )
done
IFS=$SAVEIFS
# rename the mp3 files, like 010-流年.mp3 -> 流年.mp3
# reference: http://www.cyberciti.biz/tips/handling-filenames-with-spaces-in-bash.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment