delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/04/13/13:32:26

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: ericblake AT comcast DOT net (Eric Blake)
To: Lynn Wilson <lynn AT swcp DOT com>, cygwin <cygwin AT cygwin DOT com>
Subject: Re: rm fails to remove symbolic links to directories
Date: Wed, 13 Apr 2005 17:32:06 +0000
Message-Id: <041320051732.9577.425D579600043F590000256922007456720A050E040D0C079D0A@comcast.net>
X-Authenticated-Sender: ZXJpY2JsYWtlQGNvbWNhc3QubmV0

> Just upgraded to the latest versions moments ago.
> I had created a symbolic link to a directory some time ago.
> 
> If I try and remove the symlink using Bash I get the following error:
> 
> rm: cannot remove directory `xxxxx/': Is a directory

For rm, POSIX requires that when a trailing / is applied, that the target of the symlink is affected, but when it is omitted, the symlink is affected.  It also requires that rm cannot remove directories unless you use -r, but that using -r removes what was specified (directory or otherwise).  Also, the rmdir command exists for deleting empty directories.  rm -r is powerful because it deletes directories whether they are empty or not, so sometimes you really want rmdir for the safety factor.  But rmdir does not remove symlinks, you need rm for that.

Your 'problem' is not unique to cygwin.  Observe:

$ mkdir foo
$ touch foo/file
$ ln -s foo bar
$ ls bar             # list the symlink's name
bar
$ ls bar/            # list the target's contents
file
$ rm bar/           # attempts to remove foo, which is non-empty directory
rm: cannot remove directory `bar/': Is a directory
$ rm bar             # succeeds in removing bar, which is symlink
$ ln -s foo bar
$ rm -r bar          # succeeds in removing bar, which is a symlink
$ ls foo               # only symlink was removed, foo is still intact
file
$ ln -s foo bar
$ rmdir bar
rmdir: `bar': Not a directory
$ rmdir bar/
rmdir: `bar/': Directory not empty
$ rm -r bar/        # recursively removes foo, but leaves bar intact
$ ls foo bar bar/
ls: foo: No such file or directory
bar
ls: bar/: No such file or directory

> 
> If I then empty the contents of the directory and repeat the 'rm xxxxx' command 
> I get the same error.  Trying 'rm -df xxxxx' also failed.

rm -d is a GNU extension, and only works on systems where link(2) and unlink(2) work on directories (hard-linking directories is allowed, but not required, by POSIX, and it is often discouraged because it can lead to circular directory structures and file system problems).  Cygwin is not one of those systems, so rm -d will not remove a directory.  It does not imply -r (take it upstream to the bug-coreutils list if you thing -d should imply -r).

Bash tab completion is configurable as to whether it appends / to the end of a symlink-to-a-directory.  This is controlled by `set mark-symlinked-directories on' in your ~/.inputrc.  Usually, I like it on, but in the case of removing a symlink-to-dir, it means I have to remember to manually delete the / that was appended by the tab-completion when I meant the symlink itself.

--
Eric Blake



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019