shell - About the usage of linux command "xargs" -
i have file
love.txt loveyou.txt
in directory useful
; want copy file directory /tmp
.
i use command:
find ./useful/ -name "love*" | xargs cp /tmp/
but doesn't work, says:
cp: target `./useful/loveyou.txt' not directory
when use command:
find ./useful/ -name "love*" | xargs -i cp {} /tmp/
it works fine,
i want know why second works, , more usage of -i cp {}
.
xargs
puts words coming standard input end of argument list of given command. first form therefore creates
cp /tmp/ ./useful/love.txt ./useful/loveyou.txt
which not work, because there more 2 arguments , last 1 not directory.
the -i
option tells xargs
process 1 file @ time, though, replacing {}
name, equivalent to
cp ./useful/love.txt /tmp/ cp ./useful/loveyou.txt /tmp/
which works well.
Comments
Post a Comment