GNU bug report logs - #42440
bug with rm

Previous Next

Package: coreutils;

Reported by: "����" <get55 <at> qq.com>

Date: Mon, 20 Jul 2020 10:53:02 UTC

Severity: normal

Merged with 42439

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

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 42440 in the body.
You can then email your comments to 42440 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#42440; Package coreutils. (Mon, 20 Jul 2020 10:53:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "ÌìÂí" <get55 <at> qq.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Mon, 20 Jul 2020 10:53:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "ÌìÂí" <get55 <at> qq.com>
To: "bug-coreutils" <bug-coreutils <at> gnu.org>
Subject: bug with rm
Date: Mon, 20 Jul 2020 17:51:05 +0800
[Message part 1 (text/plain, inline)]
sometimes,rm can't delete the file.
but when using rm -rf + file .
the file can be deleted.
[Message part 2 (text/html, inline)]

Merged 42439 42440. Request was from Bob Proulx <bob <at> proulx.com> to control <at> debbugs.gnu.org. (Wed, 22 Jul 2020 05:44:02 GMT) Full text and rfc822 format available.

Reply sent to Bob Proulx <bob <at> proulx.com>:
You have taken responsibility. (Wed, 22 Jul 2020 06:06:02 GMT) Full text and rfc822 format available.

Notification sent to "����" <get55 <at> qq.com>:
bug acknowledged by developer. (Wed, 22 Jul 2020 06:06:02 GMT) Full text and rfc822 format available.

Message #12 received at 42440-done <at> debbugs.gnu.org (full text, mbox):

From: Bob Proulx <bob <at> proulx.com>
To: ���� <get55 <at> qq.com>
Cc: 42440-done <at> debbugs.gnu.org
Subject: Re: bug#42440: bug with rm
Date: Wed, 22 Jul 2020 00:05:34 -0600
tags 42440 + notabug
thanks

���� wrote:
> sometimes,rm can't delete the file.
> but when using rm -rf + file .
> the file can be deleted.

This does not sound like a bug in the rm command.  Therefore I am
tagging this as such.  If you have follow up information and this
turns out to be an actual bug then we can reopen the bug report.

Unfortunately there is not enough information in the report to know
exactly the case that you are talking about.  For example I don't know
if you are talking about a literal "+" in that line or not.  I will
assume that you are since it is there.

There are several FAQs listed for rm.  Any of these might be a
problem.

  https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#How-do-I-remove-files-that-start-with-a-dash_003f
  https://www.gnu.org/software/coreutils/faq/coreutils-faq.html#Why-doesn_0027t-rm-_002dr-_002a_002epattern-recurse-like-it-should_003f

You might have experienced either of those problems.  Or a different
problem.  We can't tell.

> sometimes,rm can't delete the file.

There are two main cases.  One is that if the file is not writable by
the user then 'rm' will check for this and ask the user for
confirmation.

    rwp <at> angst:/tmp/junk$ touch file1
    rwp <at> angst:/tmp/junk$ chmod a-w file1
    rwp <at> angst:/tmp/junk$ rm file1
    rm: remove write-protected regular empty file 'file1'? n
    rwp <at> angst:/tmp/junk$ ls -l file1
    -r--r--r-- 1 bob bob 0 Jul 21 23:52 file1

The -f option will force it without prompting.

    rwp <at> angst:/tmp/junk$ rm -f file1
    rwp <at> angst:/tmp/junk$ ls -l file1
    ls: cannot access 'file1': No such file or directory

This is a courtesy confirmation.  Because the permissions on the file
is not important when it comes to removing a directory entry.  A file
is really just an entry in the directory containing it.  Removing a
file simply removes the entry from the directory.  When the last link
to the file reaches zero then the file system reclaims the storage.
The file system is a "garbage collection" system using reference
counting.

    https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)

Therefore the only permission needed to remove a file is write
permission to the directory containing it.

    rwp <at> angst:/tmp/junk$ touch file2
    rwp <at> angst:/tmp/junk$ ls -ld . file2
    drwxrwxr-x 3 rwp rwp 100 Jul 21 23:56 ./
    -rw-rw-r-- 1 rwp rwp   0 Jul 21 23:56 file2
    rwp <at> angst:/tmp/junk$ chmod a-w .
    rwp <at> angst:/tmp/junk$ ls -ld . file2
    dr-xr-xr-x 3 rwp rwp 100 Jul 21 23:56 ./
    -rw-rw-r-- 1 rwp rwp   0 Jul 21 23:56 file2

This creates a file.  The file is writable.  But I have changed the
directory containing it not to be writable.  This prevents the ability
to remove the file.  Can't remove it because the directory is not wriable.

    rwp <at> angst:/tmp/junk$ rm file2
    rm: cannot remove 'file2': Permission denied
    rwp <at> angst:/tmp/junk$ rm -f file2
    rm: cannot remove 'file2': Permission denied
    rwp <at> angst:/tmp/junk$ rm -rf file2
    rm: cannot remove 'file2': Permission denied
    rwp <at> angst:/tmp/junk$ ls -ld . file2
    dr-xr-xr-x 3 rwp rwp 100 Jul 21 23:56 ./
    -rw-rw-r-- 1 rwp rwp   0 Jul 21 23:56 file2

In order to remove the file we must have write permission to the
directory.  Adding write permission to the directory allows removing
the file.

    rwp <at> angst:/tmp/junk$ chmod ug+w .
    rwp <at> angst:/tmp/junk$ rm file2
    rwp <at> angst:/tmp/junk$ ls -ld file2
    ls: cannot access 'file2': No such file or directory

Expanding upon this problem is if there are many directories deep and
the directories are not writable.

    rwp <at> angst:/tmp/junk$ mkdir -p dir1 dir1/dir2 dir1/dir2/dir3
    rwp <at> angst:/tmp/junk$ touch dir1/dir2/dir3/file3
    rwp <at> angst:/tmp/junk$ chmod -R a-w dir1
    rwp <at> angst:/tmp/junk$ find dir1 -ls
     69649132      0 dr-xr-xr-x   3 rwp      rwp            60 Jul 22 00:00 dir1
     69649133      0 dr-xr-xr-x   3 rwp      rwp            60 Jul 22 00:00 dir1/dir2
     69649134      0 dr-xr-xr-x   2 rwp      rwp            60 Jul 22 00:00 dir1/dir2/dir3
     69650655      0 -r--r--r--   1 rwp      rwp             0 Jul 22 00:00 dir1/dir2/dir3/file3

That sets up the test case.  None of the directories are wriable.
Therefore we cannot remove any of them.  The directory holding the
entries must be writable.

    rwp <at> angst:/tmp/junk$ rm -rf dir1
    rm: cannot remove 'dir1/dir2/dir3/file3': Permission denied

Even using 'rm -rf' does not work.  And should not work.  Because the
directories are not writable.

In order to remove these files the directories must be made writable.

    rwp <at> angst:/tmp/junk$ chmod -R u+w dir1
    rwp <at> angst:/tmp/junk$ rm -rf dir1
    rwp <at> angst:/tmp/junk$ ls -ld dir1
    ls: cannot access 'dir1': No such file or directory

Hopefully this helps you understand how directory entries work, that
the directory holding an entry (either file or another directory) must
be writable.  How to add write permission.  How to remove a single
file.  How to remove a directory tree.  Hopefully this helps! :-)

Bob




Reply sent to Bob Proulx <bob <at> proulx.com>:
You have taken responsibility. (Wed, 22 Jul 2020 06:06:02 GMT) Full text and rfc822 format available.

Notification sent to "����" <get55 <at> qq.com>:
bug acknowledged by developer. (Wed, 22 Jul 2020 06:06:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#42440; Package coreutils. (Wed, 22 Jul 2020 13:18:02 GMT) Full text and rfc822 format available.

Message #20 received at 42440 <at> debbugs.gnu.org (full text, mbox):

From: "Æô³½¹¤×÷ÊÒ" <get55 <at> qq.com>
To: "42440" <42440 <at> debbugs.gnu.org>
Subject: »Ø¸´£ºbug#42440: closed (Re: bug#42440: bug with rm)
Date: Wed, 22 Jul 2020 14:08:12 +0800
[Message part 1 (text/plain, inline)]
ok,


------------------&nbsp;ԭʼÓʼþ&nbsp;------------------
·¢¼þÈË:                                                                                                                        "42440"                                                                                    <help-debbugs <at> gnu.org&gt;;
·¢ËÍʱ¼ä:&nbsp;2020Äê7ÔÂ22ÈÕ(ÐÇÆÚÈý) ÏÂÎç2:06
ÊÕ¼þÈË:&nbsp;"Æô³½¹¤×÷ÊÒ"<get55 <at> qq.com&gt;;

Ö÷Ìâ:&nbsp;bug#42440: closed (Re: bug#42440: bug with rm)



Your bug report

#42440: bug with rm

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 42440 <at> debbugs.gnu.org.

-- 
42440: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=42440
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (text/html, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 20 Aug 2020 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 250 days ago.

Previous Next


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