Skip to content

Linux: Copy a file to multiple directories

The Linux command cp does support multiple source files, but not multiple targets. Therefore one needs to use a workaround, such as

ls| xargs -n 1 cp file.dat

The command copies file.dat to all folders returned by ls.

Posted in ITechnische Post.

Tagged with , , , .

3 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Andreas Heindl says

    Nice! My solution would employ find.

    find . -type f -name * -exec cp file.dat {} \;

  2. Hermann says

    A bit more refined if you want to copy it only to selected folders
    find . -name “*MeV” -type d -exec cp ../myfile.dat {} \;