bug-coreutils
[Top][All Lists]
Advanced

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

bug#21051: direct/file deletion


From: Eric Blake
Subject: bug#21051: direct/file deletion
Date: Thu, 16 Jul 2015 08:49:29 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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