December 30, 200817 yr I need some help. On my unraid server I have a TON of MP3 files. I've been using MusicBrainz to sort them into albums and for whatever reason I've got about 900+ that have "(1)" appended to the end of the filename. If I had a shell script that could remove the "(1)" from file names a directory at a time, that would be a great help. If the script could traverse subdirectories it would be even better. Before I start to try to figure this out, can someone tell me if it is even possible to create a shell script that would rename files in this manner?
December 30, 200817 yr I need some help. On my unraid server I have a TON of MP3 files. I've been using MusicBrainz to sort them into albums and for whatever reason I've got about 900+ that have "(1)" appended to the end of the filename. If I had a shell script that could remove the "(1)" from file names a directory at a time, that would be a great help. If the script could traverse subdirectories it would be even better. Before I start to try to figure this out, can someone tell me if it is even possible to create a shell script that would rename files in this manner? Something like this will do what you want. If there is a "space" between the .mp3 and the "(1)" then change the "basename" command below to say " (1)" instead of "(1)" to strip off the full "extra" suffix. Change the "starting directory" from /mnt/disk/whatever" to your directory, or... make it "/mnt/user" to get them all at one time. Any file with ".mp3*(1)" would then be renamed. find /mnt/disk/whatever -type f -name "*.mp3*(1)" -print | while read name do new_name=`basename "$name" "(1)"` mv "$name" "$new_name" done
December 30, 200817 yr Author Joe, Thank you. When I get this to work it will save me hours of manual labor. And, I will have learned something. The first stumbling block I'm having is that I need to be able to point to directories that have spaces in them. For instance, this doesn't work: find /mnt/disk1/Media/Music/MP3/Tagged/Albums From Andy -type f -name "*(1).mp3" -print | while read name Without renaming my directories, is there a way to do this? Would quotes around the directory path do the trick?
December 30, 200817 yr And if the "(1)" appears the way I think it does, as in "mysong(1).ape"... find /mnt/disk/whatever -type f -name "*(1).*" -print | while read name do THIS PART NEEDS TO BE REDONE BY JOE L done
December 31, 200817 yr If I had a shell script that could remove the "(1)" from file names a directory at a time, that would be a great help. If the script could traverse subdirectories it would be even better. Another option that will work 1 folder at a time is this... http://www.softpedia.com/get/System/File-Management/CKRename.shtml It works from your windows box across to a mapped network drive. I've used it successfully for may different bulk renaming operations.
December 31, 200817 yr And if the "(1)" appears the way I think it does, as in "mysong(1).ape"... find /mnt/disk/whatever -type f -name "*(1).*" -print | while read name do THIS PART NEEDS TO BE REDONE BY JOE L done Yes, and I also did not deal with the "current directory" very well. Let me see if I can think of an easy way. OK, there is no need to name each directory... this single command should do it all, regardless of where the "(1)" resides in the name, and regardless of the directory name find /mnt/disk* -type f -name "*.mp3*" -print | grep "(1)" | while read name do new_name=`echo $name | sed 's/(1)//'` echo mv "$name" "$new_name" done Above I have added a "echo" to the front of the "mv" command, so it will not move (rename) anything, but print to the screen what it will do if you remove the "echo". Here is the command that will actually do the move of the file to the new name. find /mnt/disk* -type f -name "*.mp3*" -print | grep "(1)" | while read name do new_name=`echo $name | sed 's/(1)//'` mv "$name" "$new_name" done Run it exactly as it is, there is no need to go to each directory, or to change the directory name as I first suggested. It will get rid of the "(1)" in every .mp3 file on your server under /mnt/disk* If you did want to specify a directory with spaces, and not look for any file in any disk matching the pattern, you do need to quote it as follows find "/mnt/disk1/Media/Music/MP3/Tagged/Albums From Andy" -type f -name "*.mp3*" -print | grep "(1)" | while read name do new_name=`echo "$name" | sed 's/(1)//'` mv "$name" "$new_name" done You could also just "escape" the spaces (put a backslash before each space) like this, if you did not want to quote the directory find /mnt/disk1/Media/Music/MP3/Tagged/Albums\ From\ Andy -type f -name "*.mp3*" -print | grep "(1)" | while read name do new_name=`echo "$name" | sed 's/(1)//'` mv "$name" "$new_name" done Also note, if the MP3 suffix on the files is upper case, the find command would also need to be upper case. find "/mnt/disk1/Media/Music/MP3/Tagged/Albums From Andy" -type f -name "*.MP3*" -print | grep "(1)" | while read name do new_name=`echo "$name" | sed 's/(1)//'` mv "$name" "$new_name" done Joe L.
December 31, 200817 yr Author Joe - A BIG Thank You. The more I learn about the Linux environment the more I realize just how powerful the command line & scripting can be. I knew there was an elegant answer, I just don't know enough yet to create this stuff myself. I edited the script for my environment and ran it. It took about 10 minutes to pile through ~45,000 files, but it finished perfectly. jonathanm - I DL'd CKRename to check it out. It's so very too bad that it can't traverse directories. But, other than that it's a great tool to have in the box. Thank you for the suggestion.
Archived
This topic is now archived and is closed to further replies.