>>> 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

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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to