Ive got multiple mp3 files named like so:

artist - year - album - track - title.mp3

about half of them, due to a "rename from tag" error are named like this:

artist - year - album - track - title - - .mp3

how do I make the last example look like the first in ubuntu. Due to errors now in the tags, I am unable to use the tag program to rename the files with out messing up the currently correct file names, unless I spent a lot of time looking for and selecting for the mis-named files.

If I could move the mis-named files to another directory, I would be able to use the tag program to fix the file names, but how do I move ONLY the mis-named files?


migrated from stackoverflow.com Dec 2 '11 at 15:04

This question came from our site for professional and enthusiast programmers.

  • Place [part of] output of ls -1 | cat -t. – Vi. Oct 9 '11 at 20:33

If you have the utility rename, you can do something along the lines of:

rename -e 's/ - - //' *.mp3

To be safe, before you run the above, run it with the -n flag, for a dry run. It won't change any files, but will show you what it would change, like so:

$ rename -n -e 's/ - - //' *.mp3
rename(artist - year - album - track - title - - .mp3, artist - year - album - track - title.mp3)

Something like mv $(ls -1 | grep -- '- -') /path/to/dir_to_for_retagging/. Better do echo mv ... first to see what will it do.

  • mv $(ls -1 | grep -- '- -') /path/to/dir_to_for_retagging/ results in: mv: missing destination file operand after..destination directory – Key Board Oct 9 '11 at 18:24
mv *--.mp3 /path/to/dir

should work fine.

  • May be mv *' - -.mp3' /path/to/dir/? There are space characters. – Vi. Oct 9 '11 at 17:31
  • $ mv *' - - .mp3 ~/Desktop/u/ mv: cannot stat `-': No such file or directory for both dashes – Key Board Oct 9 '11 at 19:05
  • mv --.mp3 /path/to/dir mv: cannot stat `--.mp3': No such file or directory – Key Board Oct 9 '11 at 19:06

something like

for i in $(ls *--.mp3); do mv $i `echo $i | sed s/--// ; done

(untested). This'll remove all -- from the file names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy