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

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

    As far as I can see it you can use the following:

    ls | xargs -n 1 cp -i file.dat
    

    The -i option of cp command means that you will be asked whether to overwrite a file in the current directory with the file.dat. Though it is not a completely automatic solution it worked out for me.

提交回复
热议问题