Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I run the following sequence of commands:

mkdir dir
ln -s dir link
rm -r link/

I get this output:

rm: cannot remove `link': Not a directory

I get the warning because I could simply have issued rm -r link or, better still, rm link. Regardless, that command did get the job done (i.e. removed the file named "link").

Things are a bit different when doing such a thing on a mounted volume, where "dir" is replaced with some like "/media/my_movies". In such a case, the entire volume will be wiped, not just the symlink as in the previous example.

Why is it like that? Is this some bug in rm, or is this expected? Why the inconsistency?

UPDATE: Maybe I was dizzy when I was experiencing this because when I try now, "dir" is not getting deleted while its contents are, and in both cases (mounted and local directory). I'm using Linux 2.6.32, and I think I was using 2.6.37 then.

share|improve this question
The mounted volume was an NTFS partition. I haven't tried with another filesystem, so I don't know if it has anything to with it. – Tshepang Jan 28 '11 at 23:41
NTFS doesn't have an exact match for the unix concept of symbolic links. Your NTFS driver is translating between symbolic links and one of the similar concepts on NTFS, but the behavior is not exactly the same (perhaps it's using a junction point, which is closer to a hard link). – Gilles Jan 29 '11 at 12:43
See also the slash (/) after a directory name on shell commands. POSIX says that foo/ is mostly equivalent to foo/., but implementations aren't very conforming on this point (even OpenBSD: with your example, rm -r link/ just removes the link). – Gilles Jan 29 '11 at 12:49

On my system (Debian; Linux 2.6; rm --version reports GNU coreutils 8.5), whether or not dir is a mount point, the following removes file, but not dir or link, and gives me the same error you saw:

# mkdir dir && touch dir/file && ln -s dir link
# rm -r link/
rm: cannot remove `link': Not a directory
# ls
dir  link
# ls -l dir
total 0

# mount .../scratch_filesystem dir
# touch dir/file
# rm -r link/
rm: cannot remove `link': Not a directory
# ls
dir  link
# ls -l dir
total 0

If I'm following you right, your rm -r link/ command doesn't remove file, unless dir/ is a mount point. If that's the case, I think you're seeing a bug in rm. There's no good reason for a mount point to change its behavior like that.

It would be interesting to know what version of rm you're using.

share|improve this answer
my rm is the same version as yours – Tshepang Jan 29 '11 at 7:55
How odd! What happens if you do env -i /bin/rm -r link/ instead of just rm -r link/? I.e. clear the environment and avoid any potential shell aliases. – Jander Jan 29 '11 at 8:11
See my update question: I'm now getting what you are getting. If it happens again, I'll try the env thing... I wish I should have tried when I was still having the problem. – Tshepang Mar 7 '11 at 18:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.