From owner-freebsd-questions@FreeBSD.ORG Tue Apr 13 05:42:30 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D580C16A4CE for ; Tue, 13 Apr 2004 05:42:30 -0700 (PDT) Received: from smtp.infracaninophile.co.uk (ns0.infracaninophile.co.uk [81.2.69.218]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6B38E43D5C for ; Tue, 13 Apr 2004 05:42:29 -0700 (PDT) (envelope-from m.seaman@infracaninophile.co.uk) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost.infracaninophile.co.uk [IPv6:::1])i3DCgJ8i093578 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 13 Apr 2004 13:42:19 +0100 (BST) (envelope-from matthew@happy-idiot-talk.infracaninophile.co.uk) Received: (from matthew@localhost)id i3DCgJD1093577; Tue, 13 Apr 2004 13:42:19 +0100 (BST) (envelope-from matthew) Date: Tue, 13 Apr 2004 13:42:19 +0100 From: Matthew Seaman To: Peter Risdon Message-ID: <20040413124219.GA92953@happy-idiot-talk.infracaninophile.co.uk> Mail-Followup-To: Matthew Seaman , Peter Risdon , FreeBSD Question List References: <40757879.1010307@circlesquared.com> <20040408165511.GD8182@dan.emsphone.com> <407BC1F9.4050305@circlesquared.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="VS++wcV0S1rZb1Fb" Content-Disposition: inline In-Reply-To: <407BC1F9.4050305@circlesquared.com> User-Agent: Mutt/1.5.6i X-Spam-Status: No, hits=-4.8 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=2.63 X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on happy-idiot-talk.infracaninophile.co.uk X-Virus-Scanned: clamd / ClamAV version devel-20040407, clamav-milter version 0.70g cc: FreeBSD Question List Subject: Re: Problems with filename with spaces (was Pipes and commands thatrequire two arguments) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Apr 2004 12:42:31 -0000 --VS++wcV0S1rZb1Fb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Apr 13, 2004 at 11:33:29AM +0100, Peter Risdon wrote: > Thanks very much for the previous help - I missed the example in man xarg= s. >=20 > The files I am trying to manipulate include spaces in the file names,=20 > and I cannot seem to escape them effectively. If I try something like: >=20 > #find /usr/home -name *.rtf.exe -print0 | perl -p -e 's/\ /\\\ /g;' |=20 > xargs -0 -J % mv % /usr/newplace/ >=20 > Then although all spaces are preceded by backslashes I get errors every= =20 > time a space is encountered. So for a file at /usr/home/user/this is a=20 > file.rtf.exe I get file does not exist errors from mv at: > /usr/home/user/this\ > and at: > is\ > and at: > a\ > and at: > file.rtf.exe (yes, a windows virus on a network share has been busy). >=20 > I have also tried >=20 > #find /usr/home -name *.rtf.exe -print0 | perl -p -e 's/\ /\\\ /g;' >=20 > listofdodgyfiles >=20 > and the list is fine. If I paste a line into mv on the command line, it= =20 > works. If I use a simple script to read the file, same errors as=20 > mentioned above. >=20 > I'm sure I'm missing something obvious... Any nudges in the right=20 > direction would be gratefully received. Errr... how about: # find /usr/home -name '*.rtf.exe' -print0 | \ xargs -0 -J % mv % /usr/newplace/ or # find /usr/home -name '*.rtf.exe' -print0 | \ perl -n0e '($x =3D $_) =3D~ s,^.*/,/usr/newplace/,; rename $_, $x;' Note: this puts all of those files into a single directory and doesn't do anything to avoid overwriting one file with another. I assume that's what you want. This sort of thing is the whole point of '-print0' -- it sidesteps all of the things the shell does with significant characters when it turns a command line into an argument list. ie. no escaping needed. Cheers, Matthew --=20 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 --VS++wcV0S1rZb1Fb Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQFAe+ArdtESqEQa7a0RAip5AJ0eZKQjm1gV7Q8p5xBz+kdfoNHeqQCglWpp iV/A/Ke4GYY96fFnh8AqJIU= =ajiz -----END PGP SIGNATURE----- --VS++wcV0S1rZb1Fb--