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

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

    Suppose you want to copy fileName.txt to all sub-directories within present working directory.

    1. Get all sub-directories names through ls and save them to some temporary file say, allFolders.txt

      ls > allFolders.txt
      
    2. Print the list and pass it to command xargs.

      cat allFolders.txt | xargs -n 1 cp fileName.txt
      

提交回复
热议问题