3

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?

2 Answers 2

8

It's easy with a loop:

for f in /etc/*.conf; do cp -v -- "$f" "$f.orig"; done
2
  • 1
    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!
    – Jon Phenow
    Apr 8, 2011 at 15:20
  • To me it's easier this way : find . -name "*text*" -exec cp {} {}_addedtext \;
    – trogne
    Nov 30, 2016 at 16:32
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.