I have a collection of music ripped from cds, over time, and sitting on a directory on on of my hard drives. Many of these discs were ripped with a particular application which rips the songs to files which are labeled like so:
- 001_bmanilow_copacabana
- 002_bmanilow_mandy
- 003_bmanilow_i-write-the-songs
etc.
I need to search the directory tree recursively, because it is quite large an the files are on various levels.
What I would like to do, with a few simple commands, is to remove the first 4 characters from each song title and copy them (only *.mp3 and *.ogg files) into a seperate directory.
--
AndrewGrimmke - 11 Oct 2002
When dealing with (precious) data files, I usually write snippets that generate scripts, so that I can go and review what will be done before I launch it.
Assuming your files are all named similarly, and that you want to end up with a list of directories by artist, the following snippet will generate the commands you could then run:
FILES=$(find . -name '*.mp3' -type f)
for f in $FILES; do
artist=$(basename $f .mp3 | cut -f2 -d_)
song=$(basename $f .mp3 | cut -f3 -d_)
echo "[ ! -d $artist ] && mkdir -p $artist"
echo "mv $f $artist/$song.mp3"
done >/tmp/move_songs.sh
Now edit the generated script ... and run it once you're happy:
vi /tmp/move_songs.sh
bash /tmp/move_songs.sh
I'm sure there are more ways to chop this up...