Copy multiple files and append to end of filename

10,896

Solution 1

It's easy with a loop:

for f in /etc/*.conf; do cp -v -- "$f" "$f.orig"; done

Solution 2

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:
10,896

Related videos on Youtube

Jon Phenow
Author by

Jon Phenow

Updated on September 18, 2022

Comments

  • Jon Phenow
    Jon Phenow almost 2 years

    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?