Re: rm -rf .* alternatives (was: Re: I broke gnome2 *snff*)
On Sun, Oct 26, 2003 at 10:12:18AM -0500, Bijan Soleymani wrote:
> On Sun, Oct 26, 2003 at 02:10:01PM +0000, Karsten M. Self wrote:
> > on Fri, Oct 24, 2003 at 03:28:36PM +0100, Colin Watson (cjwatson@debian.org) wrote:
> > > On Fri, Oct 24, 2003 at 11:36:25PM +0930, David Purton wrote:
> >
> > > > Sadly no, I neglected to say that I could not get things to work even
> > > > using a test account and doing an rm -rf .* in $HOME.
> > >
> > > Just in case other people try this, 'rm -rf .*' is VERY DANGEROUS. '.*'
> > > expands to include '.' and '..', and if you happen to have privileges to
> > > write to the parent directory then you'll end up removing all
> > > directories *next* to your current directory as well!
> >
> > So what do folks do?
> >
> > rm -rf .?* # will expand to include ..
> >
> > rm -rf .[^.]* # seems right.
> >
> > find . -depth -print0 | xargs rm # Usually works.
> >
> > If you're really paranoid:
> >
> > chown -r peon .
> > su -c 'rm -rf .' peon
> >
> > ...which first changes ownership to a nonprivileged user, then runs the
> > rm as that user. Keeps you from mucking things up in a rootly way.
> >
> > Personally I tend to walk through trees very carefully when doing
> > deletes.
> >
> >
> > Other tips?
>
> You could always do:
> rm -r `ls -A`
>
> ls -A lists all files except "." and "..". From the ls manpage:
>
> "-A, --almost-all
> do not list implied . and .."
>
> Not to be confused with "ls -a" which does list "." and "..".
Then wouldn't
rm -r `ls`
do the trick?
--
David Jardine
"Running Debian GNU/Linux and
loving every minute of it." -Sacher M.
Reply to: