Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a number of tiff files named:

sw.001.tif
sw.002.tif
...

and I want to remove the .tif at the end of each of the files. How can I use the rename command to do this?

share|improve this question
2  
Bear in mind that NO linux or unix filesystem uses Windows or VMS-style "extensions" - it is only by convention that a suffix of the file name is ".tif" or ".c" or ".o" or ".so" or whatever. –  Bruce Ediger Mar 19 '12 at 23:07
    
That's fine... I'm importing files from windows to linux :) –  Paul Mar 19 '12 at 23:14
add comment

2 Answers

up vote 11 down vote accepted

Debian rename:

rename 's/\.tif$//' *.tif

Red Hat rename:

rename .tif '' *.tif
share|improve this answer
1  
I believe the "Debian" rename is by Larry Wall (comes with Perl?) and "Red Hat" one is from util-linux (rename.ul in Debian IIRC). –  XTL Mar 20 '12 at 14:19
    
@XTL: True. I just call them that because they're the "rename" programs found in Debian or Red Hat derivatives. –  Ignacio Vazquez-Abrams Mar 20 '12 at 14:39
    
Thanks so much! I never realized that there were different versions of 'rename'. I assume there are other subtle differences between the commands in debian & redhat. I'll have to lookup some of their differences. –  Paul Mar 20 '12 at 14:45
add comment

For a non-rename, you might do:

$ for i in *.tif; do mv -i $i `basename $i .tif`; done

(-i to warn against replacing a file)

share|improve this answer
7  
Safer faster version: for i in ./*.tif; do mv -i "$i" "${i%.tif}"; done –  jw013 Mar 20 '12 at 14:13
add comment

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.