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.

Seems like I really shouldn't need to create a script for this. I'd like to do something cp /etc/*.conf $1.orig or cp /etc/{a.conf,b.conf} _firstarg_.orig Is there a quick and painless way of doing this?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

It's easy with a loop:

for f in /etc/*.conf; do cp -v -- "$f" "$f.orig"; done
share|improve this answer
    
that'll work. For some reason I doesn't feel like bash would make us do a for loop as the simplest and quickest way, but whatever it works! Thanks a lot! –  jphenow Apr 8 '11 at 15:20

In any shell, you can use a loop:

for x in /etc/*.conf; do cp -i -- "$x" "$x.orig"; done

(Remove -i if you don't care about overwriting existing files.)

With zsh, you can use the provided function zcm (put the first three lines in your ~/.zshrc):

autoload zmv
alias zcp='zmv -C'
alias zln='zmv -L'
zcp '/etc/(*.conf)' '/etc/$1.orig'

(Add -f after zcp to overwrite any existing destination file.)

share|improve this answer

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.