Bash my files into shape.
November 21, 2009 9:37 AM   Subscribe

My command line/scripting-fu is weak. Help me clean up and copy a lot of files without having to do it by hand?

I keep a full version of my music library on an HTPC, running Ubuntu. When I acquire new music, I always do so on my Windows laptop, and I also make sure to get a high-quality image of the album cover. For various reasons, I switched a while ago from naming the cover Folder.jpg to naming it front.jpg. Periodically, I push the new stuff onto the HTPC.

Now my album art on the Ubuntu machine is a mess. There are two things I would like to do. First, I want to delete any files called "Folder.jpg" that are located in folders that also have a "front.jpg." Second, I want to copy (not move) all of the "front.jpg" files to new "Folder.jpg" files. (This is because a lot of the older Folder.jpg files are wrong, borked, or lower quality). I suppose part two could solve part one by overwriting the older Folder.jpg, but I'm not confident that the case is always the same (i.e. always Folder.jpg and not folder.jpg).

Here's the directory structure of the files: /media/Drive/Audio/Artist Name/Album Name/<song files, album art images, etc.).

I have pretty rudimentary command line skills, and I can't find any way to make cp do what I want. My intuition, though, is that there must be some automated and reasonably simple way of doing this. Any assistance with sorting this out would be greatly appreciated.
posted by sinfony to Technology (3 answers total) 4 users marked this as a favorite
Best answer: find /media -name "front.jpg" -execdir cp front.jpg Folder.jpg \;
posted by Mwongozi at 9:46 AM on November 21, 2009

Response by poster: That's done it, thanks!
posted by sinfony at 9:51 AM on November 21, 2009

Actually, you'll probably want to use '-iname' instead of '-name' since you're not sure about case.

Also, you may want to try running with 'echo' stuck before the 'cp' first and looking at the output to make sure nothing wrong is going on. (Which is not to say that Mwongozi's script is wrong--it's just a good practice with these kinds of things.)
posted by suetanvil at 9:56 AM on November 21, 2009

« Older Seeking clicking mechanism or design...   |   How do you solve a problem like Maria losing her... Newer »
This thread is closed to new comments.