Thursday, August 27, 2009

Rename Files with find command in linux

If you want to rename files recusivelly using linux find command, here are two example usage of it with exec and xargs. This command will convert all the *.xml files into *.html files.

Using xags
find . | xargs rename 's/\.xml$/\.html/i'
Using exec
find . -exec rename 's/\.xml$/\.html/i' {} +
Above commands recurrsively replace files within inner directories too. If you want to do it for current directory only you can use -prune.
i.e
find . -prune | xargs rename 's/\.xml$/\.html/i'
find . -prune -exec rename 's/\.xml$/\.html/i' {} +

1 comment: