Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Feb 2012 16:12:06 +0000
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        freebsd-questions@freebsd.org
Subject:   Re: 'rm' Can not delete files
Message-ID:  <4F3541D6.5080505@infracaninophile.co.uk>
In-Reply-To: <CAE7N2kdmbm_5=c8oNknYQE5HOrvVjtfS4XTGYvxTjEQVbGr-7Q@mail.gmail.com>
References:  <1237723287.20120207235924@yandex.ru> <4F31A260.20109@infracaninophile.co.uk> <20120207231716.31aa8bc3@gumby.homeunix.com> <20120209032544.GA58560@ozzmosis.com> <CAE7N2kdmbm_5=c8oNknYQE5HOrvVjtfS4XTGYvxTjEQVbGr-7Q@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig853E0A02FE49DEB34FD48CB7
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable


>>> ls -1 | xargs rm

>> but be aware that that wont work for filenames with spaces.

True.  Can't do that using ls to generate the list of filenames as there
is no option to generate a null-separated list amongst ls's
multitudinous collection.

> In addition, I don't believe it solves the OP's initial problem of the
> argument list being too long!  You'd probably need to use the xargs -n
> switch here.

Go and read the xargs(1) man page carefully.  xargs is specifically
designed to avoid arglist overflows.

>> Or the scenic route, using xargs, with one rm per file (slower):
>>
>> find . -type f -depth 1 -print0 | xargs -n1 -0 rm -f
>>
>> (The "scenic route" is useful if you want to do something else with
>> the files instead of deleting them with rm.)

In this case, if you're going to call rm repeatedly with only one arg,
then xargs is pretty pointless.  You might as well do:

   find . -type f -depth 1 -exec rm -f '{}' ';'

but let's not leave people in any doubt that this is not the best option.=


	Cheers,

	Matthew

--=20
Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
JID: matthew@infracaninophile.co.uk               Kent, CT11 9PW


--------------enig853E0A02FE49DEB34FD48CB7
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.16 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk81Qd0ACgkQ8Mjk52CukIyeeACdHapWiQOvKljWAEg1LuN9Jdux
oqEAnAkziwcLF6fEb6RjpQgiKlyUyDRI
=Mz77
-----END PGP SIGNATURE-----

--------------enig853E0A02FE49DEB34FD48CB7--



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