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

前端 未结 22 2038
终归单人心
终归单人心 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:04

    You can't do this with cp alone but you can combine cp with xargs:

    echo dir1 dir2 dir3 | xargs -n 1 cp file1
    

    Will copy file1 to dir1, dir2, and dir3. xargs will call cp 3 times to do this, see the man page for xargs for details.

提交回复
热议问题