Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Apr 2004 17:36:59 +0100
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        Peter Risdon <peter@circlesquared.com>
Cc:        FreeBSD Question List <freebsd-questions@freebsd.org>
Subject:   Re: Pipes and commands that require two arguments
Message-ID:  <20040408163658.GC26470@happy-idiot-talk.infracaninophile.co.uk>
In-Reply-To: <40757879.1010307@circlesquared.com>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
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

[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAdX+qdtESqEQa7a0RAjGlAJ43F4X1kk3W2EXaJenQ7/9txQ0WiQCffCrB
uAWOr0H+FV6l67VR8GQmXOo=
=3cLf
-----END PGP SIGNATURE-----
home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040408163658.GC26470>