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

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

    Essentially equivalent to the xargs answer, but in case you want parallel execution:

    parallel -q cp file1 ::: /foo/ /bar/
    

    So, for example, to copy file1 into all subdirectories of current folder (including recursion):

    parallel -q cp file1 ::: `find -mindepth 1 -type d`
    

    N.B.: This probably only conveys any noticeable speed gains for very specific use cases, e.g. if each target directory is a distinct disk.

    It is also functionally similar to the '-P' argument for xargs.

提交回复
热议问题