Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Feb 2012 14:25:44 +1100
From:      andrew clarke <mail@ozzmosis.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: 'rm' Can not delete files
Message-ID:  <20120209032544.GA58560@ozzmosis.com>
In-Reply-To: <20120207231716.31aa8bc3@gumby.homeunix.com>
References:  <1237723287.20120207235924@yandex.ru> <4F31A260.20109@infracaninophile.co.uk> <20120207231716.31aa8bc3@gumby.homeunix.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue 2012-02-07 23:17:16 UTC+0000, RW (rwmaillists@googlemail.com) wrote:

> On Tue, 07 Feb 2012 22:14:56 +0000
> Matthew Seaman wrote:
> 
> > ls -1 | xargs rm
> 
> but be aware that that wont work for filenames with spaces.

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.

The above will also try to 'rm' directories, which won't work.

Instead I would use 'find':

find . -type f -depth 1 -delete

This will also work with filenames with spaces.

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

Regards
Andrew



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