GNU bug report logs - #9950
rm -r partial failure

Previous Next

Package: coreutils;

Reported by: Graham Lawrence <gl00637 <at> gmail.com>

Date: Fri, 4 Nov 2011 16:20:01 UTC

Severity: normal

Tags: notabug

Done: Bob Proulx <bob <at> proulx.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Bob Proulx <bob <at> proulx.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#9950: closed (rm -r partial failure)
Date: Fri, 04 Nov 2011 16:36:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Fri, 4 Nov 2011 10:32:40 -0600
with message-id <20111104163240.GA9103 <at> hysteria.proulx.com>
and subject line Re: bug#9950: rm -r partial failure
has caused the debbugs.gnu.org bug report #9950,
regarding rm -r partial failure
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
9950: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9950
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Graham Lawrence <gl00637 <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: rm -r partial failure
Date: Fri, 4 Nov 2011 07:52:40 -0700
By my understanding of rm -r the files listed by find below should
have been removed by the first rm.  But it took only some of them.
Vim was not running during this process.

~ $pwd
/home/g
~ $find /home -name *swp
/home/g/.vim/config.swp
/home/g/.vim/Notes.swp
/home/g/.vim/nzb.sh.swp
/home/g/.vim/makesess.vim.swp
/home/g/.vim/backup.sh.swp
/home/g/.vim/.vimrc.swp
/home/g/.vim/.bashrc.swp
/home/g/.vim/renamer.sh.swp
/home/g/.vim/vimcht.swp
/home/g/.vim/grepnotes.sh.swp
/home/g/Scripts/.reseq.awk.swp
/home/g/.fluxbox/.menu.swp
~ $rm -rf *.swp
~ $find /home -name *swp
/home/g/.vim/Notes.swp
/home/g/.vim/backup.sh.swp
/home/g/.vim/.vimrc.swp
/home/g/Scripts/.reseq.awk.swp
/home/g/.fluxbox/.menu.swp
~ $rm -rf *swp
~ $find /home -name *swp
/home/g/.vim/Notes.swp
/home/g/.vim/backup.sh.swp
/home/g/.vim/.vimrc.swp
/home/g/Scripts/.reseq.awk.swp
/home/g/.fluxbox/.menu.swp
~ $rm -f /home/g/.vim/Notes.swp
~ $rm /home/g/.vim/backup.sh.swp
~ $rm /home/g/.vim/.vimrc.swp
~ $rm /home/g/Scripts/.reseq.awk.swp
~ $rm /home/g/.fluxbox/.menu.swp
~ $find /home -name *swp
~ $


[Message part 3 (message/rfc822, inline)]
From: Bob Proulx <bob <at> proulx.com>
To: Graham Lawrence <gl00637 <at> gmail.com>
Cc: 9950-done <at> debbugs.gnu.org
Subject: Re: bug#9950: rm -r partial failure
Date: Fri, 4 Nov 2011 10:32:40 -0600
tags 9950 + notabug
thanks

Graham Lawrence wrote:
> By my understanding of rm -r the files listed by find below should
> have been removed by the first rm.  But it took only some of them.
> Vim was not running during this process.

Thank you for your bug report.  However this is simply a
misunderstanding of the shell file glob expansion of your shell and
not a bug in rm.

> ~ $pwd
> /home/g

You are in your home directory.

> ~ $find /home -name *swp
> /home/g/.vim/config.swp
> /home/g/.vim/Notes.swp
> /home/g/.vim/nzb.sh.swp
> /home/g/.vim/makesess.vim.swp
> /home/g/.vim/backup.sh.swp
> /home/g/.vim/.vimrc.swp
> /home/g/.vim/.bashrc.swp
> /home/g/.vim/renamer.sh.swp
> /home/g/.vim/vimcht.swp
> /home/g/.vim/grepnotes.sh.swp
> /home/g/Scripts/.reseq.awk.swp
> /home/g/.fluxbox/.menu.swp

There are twelve .swp files in subdirectories.  There are none in the
current directory.

> ~ $rm -rf *.swp

That will not match any files.  No files will be deleted.

You can verify that no files are matched by using the 'echo' command.
I will assume 'bash' for the following examples.

  $ echo ls -ldog *.swp
  ls -ldog *.swp

See?  No files are matched by the "*.swp" file glob.  The shell could
not find any and so the option argument was left unchanged.  If it had
matched files then the actual files would have been replaced on that
option argument.  For example:

  $ touch file1.test
  $ echo ls -ldog *.test
  ls -ldog file1.test

See how the file glob is replaced *by the shell* with the matching
files.  At this point your problem should be clear.  The file glob is
not matching any files and therefore rm isn't removing any.  rm isn't
complaining because the rm -f option tells it not to complain about
files that do not exist.  The string "*.swp" is a file that does not
exist.

> ~ $rm -f /home/g/.vim/Notes.swp
> ~ $rm /home/g/.vim/backup.sh.swp
> ~ $rm /home/g/.vim/.vimrc.swp
> ~ $rm /home/g/Scripts/.reseq.awk.swp
> ~ $rm /home/g/.fluxbox/.menu.swp
> ~ $find /home -name *swp
> ~ $

Right.  Here you have told rm to remove the files individually.  So of
course that works.

If you want to find files and then remove them you should use find.
And you are *already* using find.  So this should be natural.

  $ find /home -name '*.swp' -ls
  ...verify your file list...

  $ find /home -name '*.swp' -delete

Using -delete is a new option.  The traditional method would be to use
the rm command with find.

  $ find /home -name '*.swp' -exec rm -f {} +

Using find provides a powerful file finding mechanism that works with
all of the rest of the utilities.  It is a general solution.

Please also see this reference for more information:

  http://www.gnu.org/software/coreutils/faq/#Why-doesn_0027t-rm-_002dr-_002a_002epattern-recurse-like-it-should_003f

And also this one too:

  http://www.gnu.org/software/coreutils/faq/#Why-doesn_0027t-rm-_002dr-_002a_002epattern-recurse-like-it-should_003f

Bob


This bug report was last modified 13 years and 200 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.