Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I rename all files in a directory, recursively, changing one file extension to another, for thousands of files in thousands of subfolders? I see a lot of commands that do almost what I want, but not quite.

find . -name "*.andnav" -exec rename .andnav .tile {} \;
syntax error at (eval 1) line 1, near "."


rename -nv 's/\.andnav$/\.tile/i' *.andnav
0.png.andnav renamed as 0.png.tile
share|improve this question
Do you have Debian rename or Red Hat rename? – Ignacio Vazquez-Abrams Nov 20 '10 at 16:42
@Ignacio: Ubuntu = Debian? – endolith Nov 20 '10 at 16:44
Yes, Ubuntu is a Debian derivative. – Ignacio Vazquez-Abrams Nov 20 '10 at 20:39
up vote 16 down vote accepted

Figured it out

find . -name "*.andnav" -exec rename -v 's/\.andnav$/\.tile/i' {} \;
./0/0.png.andnav renamed as ./0/0.png.tile
./0/1.png.andnav renamed as ./0/1.png.tile
./1/0.png.andnav renamed as ./1/0.png.tile
./1/1.png.andnav renamed as ./1/1.png.tile

of course remove the -v when actually doing it, or it will waste time displaying all the files

share|improve this answer

Something like:

find . -name '*.andnav' -exec sh -c 'mv "$0" "${0%.andnav}.tile"' {} \;
share|improve this answer
this one worked best for me – cwd Jul 17 '11 at 21:04

With zsh:

autoload zmv
zmv -n '(**/)(*).andnav' '$1$2.tile'

Remove the -n to actually perform the renaming.

share|improve this answer
Fantastic answer! – Chris Knadler Apr 17 '13 at 17:33

I found this method is easier and easier to read:

find . -name "*.andnav" | rename "s/\.andnav$/.tile/"

At least on Ubuntu derivations rename takes a list of files from STDIN if none are on the command line. And this can be tested easily with:

find . -name "*.andnav" | rename -vn "s/\.andnav$/.tile/"

until you get it right.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.