GNU bug report logs -
#21051
direct/file deletion
Previous Next
Reported by: Lee Sung <lsung <at> juniper.net>
Date: Mon, 13 Jul 2015 21:44:02 UTC
Severity: normal
Tags: notabug
Done: Assaf Gordon <assafgordon <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
On 07/16/2015 07:20 AM, Ruediger Meier wrote:
> On Wednesday 15 July 2015, Lee Sung wrote:
>>> How would I delete directory "." and ".."
>>
>> Those entries are required infrastructure and should not be deleted.
>> The "." directory refers to the current directory. The ".." refers
>> to the parent directory. The ".." entry on some classic Unix file
>> systems may be unlinked but I don't believe that any current Linux
>> file system allows this. This is a restriction imposed by the kernel
>> and not by coreutils.
>
> I understand why "." and ".." links can't or at least should not be
> removed. And maybe it would be also inconsistent behavior to follow
> these links and to remove the original target directory.
>
> But I don't understand why "rm -rf ." does not delete at least all
> content within ".".
Because POSIX says so:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html
"If either of the files dot or dot-dot are specified as the basename
portion of an operand (that is, the final pathname component) or if an
operand resolves to the root directory, rm shall write a diagnostic
message to standard error and do nothing more with such operands."
If you think POSIX is wrong, and should allow 'rm -rf .' as a way to
empty '.' while leaving the directory itself intact (but probably still
failing the overall command and setting $? to 1), then propose a bug
report to the POSIX folks (especially helpful would be if you could
provide evidence that historical Unix from 30 years ago behaved in that
manner, and that it was an inadvertent wording choice in POSIX that
prevents the historical behavior):
http://austingroupbugs.net/main_page.php
>
> My use case would be to cleanup "build" directories to start freshly
> like this:
>
> $ pwd
> /home/rudi/devel/coreutils/=build-1234
> $ rm -rf .
> $ ../configure
>
> IMO all workarounds to cleanup "." (inclusive dot-files) are just
> annoying.
These work (but I agree that they are much longer to type)
rm -rf -- * .??* .[!.]
(except that has problems with command line length)
find . \! -name . | xargs rm -rf
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
This bug report was last modified 6 years and 218 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.