bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#9950: rm -r partial failure


From: Bob Proulx
Subject: bug#9950: rm -r partial failure
Date: Fri, 4 Nov 2011 10:32:40 -0600
User-agent: Mutt/1.5.21 (2010-09-15)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]