Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

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


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.