quickly change all .html extensions on files in folder to .htm

for i in *.html ; do mv $i ${i%.html}.htm ; done

13
By: scubacuda
2009-03-03 16:10:18
mv

What Others Think

what is wrong with rename .htm .html *.htm
TheBunman · 561 weeks and 2 days ago
@theBunman it's still quite clever :D
linuxrawkstar · 561 weeks and 2 days ago
Under ubuntu linux, the 'rename' command is a perl script from the 'perl' package, and requires a unix find/replace expression such as rename 's/\.bak$//' *.bak would strip the .bak from all files so named.
bwoodacre · 561 weeks and 2 days ago
Broken if filename contains whitespaces. Try: ls -d *.html | sed 's/\(.*\).html$/mv "&" "\1.htm"/' | sh
OJM · 561 weeks and 1 day ago
Quotation marks "" around a variable reference are always a good practice - as it is the code breaks if filenames have spaces in them.
asmoore82 · 560 weeks and 4 days ago
I tried this command but did not work. So I changed to for i in *.html ; do mv $i ${i%.html}.htm ; done
unixmonkey20728 · 450 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: