//View Tip #571
Similar Tips
» Directories and its size
» Fix the previous command
» Bash efficiency formula ;-)
» Stream shell commands to Twitter
» Insert last argument


Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
And again about file extension changing.

There are two tips about this:
#27 - http://www.shell-fu.org/lister.php?id=27
#544 - http://www.shell-fu.org/lister.php?id=544

I'm happy to provide one more variant. It's up to you which one is the most useful.
function chext(){
  local fname
  local new_ext="$1"
  for fname in $@
    mv "$fname" "${fname%.*}.$new_ext"

If you place this function into .bashrc, then you may use it like as follows:
chext new_ext *.old_ext
chext html `find ~ -iname "*.htm"`
find ~ -iname "*.htm" | xargs chext html

View Comments »


Add your comment

Comments are currently disabled
Why not use rename?
rename 's/htm$/html/' *.htm
Posted 2009-03-17 19:21:27
Rename was also suggested here: http://www.shell-fu.org/lister.php?id=47
Posted 2009-03-17 21:31:31
Just because 'rename' may be not available on Solaris, HP-UX and other UNIX'es.
Posted 2009-03-23 07:27:47
If GNU Parallel http://www.gnu.org/software/parallel/ is installed:

   find | parallel mv {} {.}.newext
Posted 2010-06-22 04:54:57

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit