There is a directory YYY
and a structure on the site:
site1.ru/wp-content/plugins/
site2.ru/wp-content/plugins/
...
site10.ru/wp-content/plugins/
Task: YYY
directory to copy all directories plugins
which are available on the server.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communitycp
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.
dir
s. 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"
done
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:
ret=0
for d in */wp-content/plugins/; do
cp -Rp YYY "$d" || ret=1
done
return $ret # from a function; `exit $ret` in a script
YYY
to all plugin directories, or is it the other way round? – Incognito Feb 13 '13 at 10:07