How to copy a file to multiple directories using the gnu cp command

前端 未结 22 2071
终归单人心
终归单人心 2020-12-02 03:25

Is it possible to copy a single file to multiple directories using the cp command ?

I tried the following , which did not work:

cp file1 /foo/ /bar         


        
22条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 04:07

    This will copy to the immediate sub-directories, if you want to go deeper, adjust the -maxdepth parameter.

    find . -mindepth 1 -maxdepth 1 -type d| xargs -n 1 cp -i index.html
    

    If you don't want to copy to all directories, hopefully you can filter the directories you are not interested in. Example copying to all folders starting with a

    find . -mindepth 1 -maxdepth 1 -type d| grep \/a |xargs -n 1 cp -i index.html
    

    If copying to a arbitrary/disjoint set of directories you'll need Robert Gamble's suggestion.

提交回复
热议问题