Rename *.MP3 *.Mp3 *.mP3 etc.. to *.mp3.

find ./ -iname "*.mp3" -type f -printf "mv '%p' '%p'\n" | sed -e "s/mp3'$/mp3'/I" | sh
Extensible to other ugly extensions like *.JPG, *.Jpg etc.. Leave out the last pipe to sh to perform a dry run.

-1
By: jnash
2009-03-27 13:42:40

What Others Think

People- there's a search bar at the top called 'Grep the archive'. I think we've covered every last known scenario with find... 10 times. Something new perhaps?
atoponce · 880 weeks and 6 days ago
well.. I thought using the case insensitive switch of find and sed was something useful. But I yeah I agree with you too.. find has been beaten to death here :D
jnash · 880 weeks and 6 days ago
Shorter version: find . -iname \*.mp3 | sed -e 's/.*/mv & &/' -e s/.mp3$/.mp3/I | sh
penpen · 880 weeks and 6 days ago
your scripts only work for a subset of filenames try this for size : touch 'a b c' 'valid filename' and see how they fare
maht · 880 weeks and 5 days ago
@penpen: I'm not sure your version handles spaces although with that addition even it'd still come shorter :) @maht: I should've included the -print0 option in find and used xargs with -0 I guess
jnash · 880 weeks and 5 days ago
if you only have mp3s in a dir you can also use a mmv. mmv "*" "#l1" l= lowercase u=uppercase
lied · 879 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: