Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

There is a directory YYY and a structure on the site:


Task: YYY directory to copy all directories plugins which are available on the server.

share|improve this question

migrated from stackoverflow.com Feb 13 '13 at 17:41

This question came from our site for professional and enthusiast programmers.

What have you tried? –  fedorqui Feb 13 '13 at 10:00
Apart from what have you tried, do you want to copy directory YYY to all plugin directories, or is it the other way round? –  Incognito Feb 13 '13 at 10:07
Plus this question has nothing to do with programming. –  iiSeymour Feb 13 '13 at 10:08
I need to copy a directory YYY (with plugin for Wordpress) in all "plugins" directories on my server. –  user2067861 Feb 13 '13 at 10:36

2 Answers 2


only can copy only to one destination , so you have to use a loop or do something like

echo dir1 dir2 dir3 | xargs -n 1 cp file1

Which 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.

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

share|improve this answer
Breaks on whitespace –  Kevin Feb 14 '13 at 0:39
whitespace in dir name or file name ? u should be able to use "dir1" "dir2" and so on to stop that problem –  Dukeatcoding Feb 14 '13 at 8:38
Quotes won't help for the dirs. They are interpreted by the shell and passed to exho, which prints them separated by a space. xargs then splits on whitespace, so how is it supposed to know whether the space was meant to be split on or a part of the name? –  Kevin Feb 14 '13 at 13:34

cp only takes one destination at a time, so call it in a loop.

for d in */wp-content/plugins/; do
  cp -Rp YYY "$d"

Note that this snippet will keep going if any of the cp commands fail. To abort immediately on failure, run set -e first. To keep going (makes sense on permission denied, not on disk full) but still report errors, save the return status in a variable:

for d in */wp-content/plugins/; do
  cp -Rp YYY "$d" || ret=1
return $ret      # from a function; `exit $ret` in a script
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.