Reputation: 2873
# cat /tmp/foo
- regular file
/lib/a.lib
/lib/b.lib
/lib/c.lib
/lib/d.lib
cat /tmp/foo | xargs cp /tmp/fred
cp: target /lib/d.lib is not a directory
Upvotes: 6
Views: 9778
Reputation: 2160
As answered by Sinan Ünür
cat /tmp/foo | xargs cp -t /tmp/fred
if no -t support
( cat /tmp/foo; echo /tmp/fred ) | xargs cp
Upvotes: 1
Reputation: 2350
Assuming /tmp/fred is a directory that exists, you could use a while loop
while read file
do
cp $file /tmp/fred
done < /tmp/foo
Upvotes: 0
Reputation: 118148
Assuming /tmp/fred
is a directory, specify it using the -t
(--target-directory
option):
$ cat /tmp/foo | xargs cp -t /tmp/fred
Upvotes: 6
Reputation: 37807
Your version of xargs probably accepts -I
:
xargs -I FOO cp FOO /tmp/fred/ < /tmp/foo
Upvotes: 3
Reputation: 146093
xargs normally places its substituted args last. You could just do:
$ cp `cat /tmp/foo` /tmp/fred/.
If it's really just the lib files, then cp /lib/?.lib /tmp/fred/.
would naturally work.
And to really do it with xargs
, here is an example of putting the arg first:
0:~$ (echo word1; echo word2) | xargs -I here echo here how now
word1 how now
word2 how now
0:~$
Upvotes: 13
Reputation: 89085
The destination directory needs to be the last thing on the command line, however xargs
appends stdin to the end of the command line so in your attempt it ends up as the first argument.
You could append the destination to /tmp/foo before using xargs, or use cat in backticks to interpolate the sorce files before the destination:
cp `cat /tmp/foo` /tmp/fred/
Upvotes: 0
Reputation: 11975
Why not try something like:
cp /lib/*.lib /tmp/fred
I think your command is failing because xargs creates the following command:
cp /tmp/fred /lib/a.lib /lib/b.lib /lib/c.lib /lib/d.lib
That is, it ends up trying to copy everything to /lib/d.lib, which is not a directory, hence your error message.
Upvotes: 0