I was trying this command...am I going correct? other there is better way

I was trying to copy all debs from apt cache to some storage location and I was taking this approach...

/var/cache/apt/archives# ls -1 | grep -v jdownloader | fgrep .deb | xargs cp /media/eshant/L-STORE/Softwares/openjdk/

an error bla_bla.deb is a not directory stalled me

Suggestions please...

Do any of the file names have embedded blanks? That's my first guess as cause of problem.

ls | grep -v jdownloader | fgrep .deb | grep " "

You can try this pax :

cd /var/cache/apt/archives
pax -rw -s '/jdownloader*//' *.deb /media/eshant/L-STORE/Softwares/openjdk/

no there is none such pattern

That surprises me. :mad: The reason I suspected is as follows:

$ ls -1
xxx
yyy
zzz zzz
$ ls | grep " "
zzz zzz
$ ls -1 | xargs cp /tmp/
cp: target `zzz' is not a directory

Are you seeing same error message? What exact error message do you see?

Any chance other "funny" character (besides a blank) in the file names? Try something like:

ls | grep "[[:cntrl:]]"

Use below command :

cd to that directory ;

find . ! -name "*jdownloader*" -name "*.deb" -exec cp {} /media/eshant/L-STORE/Softwares/openjdk/ \;

Let me know if it works ..I am not sure why your command is not working. I also checked but facing same problem for your command. But try find command to get it done.

That will work.
It will also solve the primary problem: xargs appends arguments to the given one, while cp needs the given destination last.

As MadeInGermany pointed out, cp is failing because xargs calls it with multiple arguments and the final argument is not a directory.

Further, if the use of fgrep is intended to select files that end with a .deb extension, then it is incorrect. That fgrep will match filenames with a .deb embedded at any spot. The correct filter would be grep '\.deb$' , which anchors the pattern to the end of the name.

A minor nit: you don't need to use -1 with ls when writing to a pipe. ls detects the situation automatically.

One possible, portable approach:

ls | sed '/\.deb$/!d; /jdownloader/d' | pax -rw /media/eshant/L-STORE/Softwares/openjdk/

Regards,
Alister

You're right. It was a basic problem with the command line. xargs appends arguments. It should have been:

xargs -I FILE cp FILE /media/eshant/L-STORE/Softwares/openjdk/

Or, if it only needs to run on a GNU userland, cp -t dir ... .

Regards,
Alister