[ILUG] xargs question..

From: Padraig Brady (padraig at domain linux.ie)
Date: Fri 05 Jul 2002 - 17:23:10 IST


> Hi,
>
> I have a list of files I want to move to another dir eg
>
> FF03027E-23EA-11D5-9891-00508BEE0314.PDF
> FF0308AF-23EA-11D5-9891-00508BEE0314.PDF
> FF030BA1-23EA-11D5-9891-00508BEE0314.PDF
>
> Im using xargs i.e.
>
> cat badfiles.txt | xargs -i mv /completefiles/\{\} /badfiles\{\}
>
> however xargs seems to be truncating the filenames
>
> : No such file or directory7E-23EA-11D5-9891-00508BEE0314.PDF
> : No such file or directoryAF-23EA-11D5-9891-00508BEE0314.PDF
> : No such file or directoryA1-23EA-11D5-9891-00508BEE0314.PDF
>
> Anyone see were am going wrong?

Well multiple things going on here. Your exact problem is a
missing / after badfiles I think. However there are 3 other
"problems":

1. useless use of cat. cat is for concatenating. If you just
    want to pass a file to stdin, then use the shell < operator, like:

< badfiles.txt xargs ...

2. Inefficient use of mv. Your starting a seperate process for each file
    Instead you should do:

< badfiles.txt xargs mv --target-directory=badfiles

3. It's OK in your case, but the filenames could contain quotes, spaces,
    etc. that could cause problems. Therefore the following form would
    be the best:

< badfiles.txt tr '\n' '\0' | xargs -r0 mv --target-directory=badfiles

Padraig



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:17:42 GMT