Pipes and commands that require two arguments

Matthew Seaman m.seaman at infracaninophile.co.uk
Thu Apr 8 09:37:11 PDT 2004


On Thu, Apr 08, 2004 at 05:06:17PM +0100, Peter Risdon wrote:

> I want to redirect the output of a command to mv(1) as the source file, 
> and specify somehow a destination directory. Basically, I have to move 
> several thousand files whose names match a number of patterns to a 
> single directory.
> 
> Any suggestions will be gratefully received.

There's several ways of doing this.  Assuming you've got a command
"listfiles" which returns the list of files you want moved from the
current directory:

    % mv `listfiles` /destination/directory/

If the number of files to move is larger than the maximum number of
command linearguments:

    #!/bin/sh

    for f in `listfiles` ; do
        mv $f /destination/directory/
    done

or you can use xargs(1):

    listfiles | xargs -J % mv % /destination/directory/


	Cheers,

	Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20040408/02671c00/attachment.bin


More information about the freebsd-questions mailing list