Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
1  
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

3 Answers 3

up vote 12 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

Your Answer

 
discard

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.