tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/44246: enhance mv to work better with xargs



"James K. Lowden" wrote:

> On Mon, 14 Jan 2013 13:15:28 -0800 (PST)
> Paul Goyette <paul%whooppee.com@localhost> wrote:
> 
> > >   $ echo * newdir | xargs mv
> > >
> > > works.
> > 
> > It only works while the expansion of * is shorter than xargs's
> > maximum command length.  Once you exceed that limit, you fail.
> 
> Hmm?  xargs has no internal "maximum command length" afaik.  xargs
> reads from stdin and invokes mv with execve(2).  execve may fail with
> E2BIG, but not because of how the xargs command line is formed.  

xargs' "maximum command length" is documented in the man page - look at
the -s option.

Here's a contrived example of how your mv command could fail:

        thoreau 21117> cd /tmp
        thoreau 21118> jot 10 0 | xargs touch
        thoreau 21119> mkdir a
        thoreau 21120> echo [0-9] a | xargs -t mv
        mv 0 1 2 3 4 5 6 7 8 9 a
        thoreau 21121> ls a
        a:
        0  1  2  3  4  5  6  7  8  9
        thoreau 21122> rm -r a
        thoreau 21123>
        thoreau 21123> jot 10 0 | xargs touch
        thoreau 21124> mkdir a
        thoreau 21125> echo [0-9] a | xargs -s 20 -t mv
        mv 0 1 2 3 4 5 6 7
        usage: mv [-fiv] source target
               mv [-fiv] source ... directory
        mv 8 9 a
        Exit 123
        thoreau 21126> ls a
        a:
        8  9
        thoreau 21127> 

Cheers,
Simon.


Home | Main Index | Thread Index | Old Index