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'm trying to find certain files with the name "stringx" and replace the name (but not the extension) with "stringy". So basically for stringx.txt and stingx.cs, I'd want stringy.txt and stringy.cs. I've attempted to test my rename command regex using following, but it returns no results:

rename -n 'stringx./s/\*$stringy./\/' stringx.*

I'm running csh under Centos. I can see that my regex is probably not correct, but I can't see any results to verify this. I can see that there are files that are named stringx. with the following:

find ./ -name 'stringx.*'
share|improve this question
    
I've also tried this with no success stackoverflow.com/questions/1086502/… –  Aaron Newton Nov 16 '11 at 23:33

1 Answer 1

up vote 5 down vote accepted
rename stringx stringy stringx.*

There are (at least) two utilities called rename on typical Linux systems. Debian and derived distributions (including Ubuntu) ship a Perl script whose syntax would be

rename 's/stringx/stringy/' stringx.*

On other distributions, including CentOS, rename is from util-linux, and its syntax is what I wrote above. This utility is available under the name rename.ul on Debian and derivatives.

If you want to recurse in subdirectories, assuming that by csh you mean tcsh (but really, think of entering the mid-1990s and switching to zsh):

set globstar
rename stringx stringy stringx.* **/stringx.*
share|improve this answer
    
"There are numerous inconsistencies in your example names. I assume you means you have files called stringx dot something and want to rename them to stringy dot something." - correct - I have updated the question. As for shells, the decision to use c-shell is non-trivial. However, the last option you suggested seems to work nicely - thank you. –  Aaron Newton Nov 16 '11 at 23:45
    
Gilles, I thought about your comment today - "but really, think of entering the mid-1990s and switching to zsh" - and you have a point here. For my non- csh dependent stuff, I installed zsh. I also have screen installed now, so I can create a new screen (which will be in the same working directory I was just in), type in zsh and voila - I'm in the mid-1990s. I'm not sure that everything works identically as if I'd set zsh to the default shell for that user, but it does seem to simplify things (e.g. I can get a directory listing when I use ls and <tab>). –  Aaron Newton Dec 2 '11 at 12:52

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.