//View Tip #571
Similar Tips
» Manipulate Bash sockets using /dev/tcp
» Find last modified files on a filesystem
» Create a Terminal Calculator
» Changing file extensions
» Close shell keeping all subprocess running

 

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"
  shift
  IFS=$'\n'
  for fname in $@
  do
    mv "$fname" "${fname%.*}.$new_ext"
  done
}

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 »




Comments 

Add your comment

Comments are currently disabled
rygwdn
Why not use rename?
rename 's/htm$/html/' *.htm
Posted 2009-03-17 19:21:27
John
Rename was also suggested here: http://www.shell-fu.org/lister.php?id=47
Posted 2009-03-17 21:31:31
author
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