I\'m trying to sort all mp3 files by artist and name. At the moment, they\'re in 1 giant file name. E.g Artist - Song name.mp3 I want to convert this to Artist/Song name.mp
Assuming there are many files, it's probably much faster to do this using pipes instead of a for loop. This has the additional advantage of avoiding complicated bash-specific syntax and using core unix/linux command line programs instead.
find *-*.mp3 |
sed 's,\([^-]\+\)\s*-\s*\(.*\),mkdir -p "\1"; mv "&" "\1"/"\2",' |
bash
Explanation:
This find to find all the files matching -.mp3 in the current directory.
This sed command changes each line to a command string, e.g.:
aaa - bbb.mp3
->
mkdir -p "aaa"; mv "aaa - bbb.mp3" "aaa"/"bbb.mp3"
The bash command runs each of those command strings.