[Centos] help with xargs and mv

Dag Wieers dag at wieers.com
Wed Feb 9 16:55:57 UTC 2005


On Wed, 9 Feb 2005, James B. Byrne wrote:

> On 8 Feb 2005 at 23:14, Dag Wieers wrote:
> 
> > Compare this:
> > 
> >  echo -e "file1\nfile2\nfile3" | xargs echo '{}' blah
> > 
> > with:
> > 
> >  echo -e "file1\nfile2\nfile3" | xargs -i echo '{}' blah
> 
> Thank you for the advice on the -i switch. I had tried this 
> earlier.  With the -i '{}' argument added then this is the result:
> 
> # ll -d ./mqueue/offline
> drwxr-xr-x    2 root     root         4096 Feb  8 14:03 ./mqueue/offline
> #
> # cat workmv | xargs -i '{}' mv ./mqueue/'{}' ./mqueue/offline
> xargs: {}: No such file or directory
> #
> # cat workmv | xargs -i '{}' mv ./mqueue/'{}' ./mqueue/offline/
> xargs: {}: No such file or directory
> #
> # cat workmv | xargs -i '{}' mv --Target-Directory=./mqueue/offline ./mqueue/'{}'
> xargs: {}: No such file or directory
> #
> # cat workmv | xargs -i '{}' mv --Target-Directory=./mqueue/offline/ ./mqueue/'{}'
> xargs: {}: No such file or directory
> #
> 
> P.S.
> Also, thank you very much for the depository that you run. I use 
> several of your packages.

Let me show you the manual entry again:

       --replace[=replace-str], -I replace-str, -i[replace-str]
              Replace  occurences  of  replace-str  in the initial
              arguments  with  names  read  from  standard  input.
              Also,  unquoted  blanks  do not terminate arguments.
              If replace-str is omitted, it defaults to "{}" (like
              for 'find -exec').  Implies -x and -L 1.

So you either do:

	echo -e "file1\nfile2\nfile3" | xargs -i echo '{}' blah
or	echo -e "file1\nfile2\nfile3" | xargs -i echo '{}' blah/'{}'
or	echo -e "file1\nfile2\nfile3" | xargs -i'**' echo '**' blah
or	echo -e "file1\nfile2\nfile3" | xargs -I '**' echo '**' blah

This is correct:

	xargs -i'{}'
or	xargs -I '{}'

This is not:

	xargs -i '{}'

Compare this to the manual entry to verify. The distinction is necessary 
and important to allow for an '{}' default replace-str. Otherwise xargs 
wouldn't know whether the next argument is in fact the replace-str or the 
command to run !

--   dag wieers,  dag at wieers.com,  http://dag.wieers.com/   --
[all I want is a warm bed and a kind word and unlimited power]



More information about the CentOS mailing list