cp after xargs not working
While you already know how you should solve your current problem, I'll still answer about xargs
.
xargs
puts the string it got in the end of command, while in your case you need that string before the last argument of cp
. Use -I
option of xargs
to construct the command. Like this:
ls /source/path/*pattern* | xargs -I{} cp -u {} /destination/path
In this example I'm using {}
to as a replacement string, so the syntax looks similar to find
.
ls -al /var/cache/apt/archives/ |
grep 'i386' |
awk '{print $9}'
can be simplified to /var/cache/apt/archives/*i386*
So, use either of these two:
cp -u /var/cache/apt/archives/*i386* /home/alex/debian-share/apt-archives/
cp -ut /home/alex/debian-share/apt-archives/ /var/cache/apt/archives/*i386*
where
-t, --target-directory=DIRECTORY
copy all SOURCE arguments into DIRECTORY
See also info on parsing ls