I run debian jessie on Host 64-bit and in virtualbox 32-bit. To spare traffic I try to cp the i386 packages from host to the shared folder, for using them in virualbox.

My Hostname/var/cache/apt/archives$ ls -al /var/cache/apt/archives/ |
    grep 'i386' | 
    awk '{print $9}'

Shows me the packages I'm looking for. but them I try to cp them after xargs

My Hostname/var/cache/apt/archives$ ls -al /var/cache/apt/archives/ |
    grep 'i386' |
    awk '{print $9}' |
    LANG=C xargs cp -u /home/alex/debian-share/apt-archives/
cp: target 'zlib1g_1%3a1.2.8.dfsg-2+b1_i386.deb' is not a directory

I can not figure out what I am doing wrong. Is this way even possible?

My problem is I can not script. Probable it is somthing like that

for i in *_i386.deb ; do cp [option] full-path to shared-folder

I didn't dry, because I will not mess my Host.

  • 1
    I think you meant to use cp -t instead of cp -u ? – Sundeep Mar 5 '17 at 10:29
  • No I mean -u -u, --update copy only when the SOURCE file is newer than the destination file or when the destination file is missing – user192526 Mar 5 '17 at 10:33
  • also, whole thing can be simplified I feel.. something like cp -ut /home/alex/debian-share/apt-archives/ /var/cache/apt/archives/*i386* .. please try this on some other sample directories – Sundeep Mar 5 '17 at 10:42
  • That works. I'm thinkinng sometimes to complicated. ^^ Make your comment to an answer, so I can except this. – user192526 Mar 5 '17 at 11:08
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*


   -t, --target-directory=DIRECTORY
          copy all SOURCE arguments into DIRECTORY

See also info on parsing ls

| improve this answer | |

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.

| improve this answer | |
  • 3
    is the {} arbitrary? could I do -Iblah for example? – nterry Jun 19 '18 at 19:57
  • 1
    Yes, you could. – aragaer Jun 20 '18 at 4:36
  • 2
    on mac without -u – jancha May 27 '19 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy