Subject: Re: Linux emulation and mkdir with trailing /
To: NetBSD Kernel Technical Discussion List <>
From: Alan Barrett <>
List: tech-kern
Date: 09/25/2000 18:52:16
On Mon, 25 Sep 2000, Greg A. Woods wrote:
> > But if I ever type a name with a trailing slash, then I intend that name
> > to be interpreted as a directory, and I expect to get an error if it
> > is a (non-directory) file.  For example, if foo exists as a file and I
> > say "mv foo bar/", then I want to get an error if bar does not already
> > exist as a directory; I certainly don't want to end up with bar as a
> > file.
> Why not?  If you don't know for sure that "bar" is an existing directory
> file before you run such a command then why would you expect the
> trailing '/' to do anything special?

If bar is a non-directory file, why would you expect to be able to
open "bar/" (with a trailing slash)?  What's the point of the trailing

I expect '/' to mark directories.  My expectation is based on
observing patterns of behaviour.  The only use I know for slashes in a
unix-like filesystem is to mark the root of the filesystem and to
separate components where all components (except perhaps the last) are
directory names.  In my limited experience, I have never encountered
any use for a trailing slash after a non-directory file name, nor seen
anybody deliberately put trailing slashes after a non-directory file
name.  Whenever I have seen a slash in a filename, the slash has been
used either to indicate the root of the filesystem, or to mark the
thing before the slash as a directory.  Whenever I have seen other
people use trailing slashes in filenames on a unix-like system, those
other people have intended to name a directory.  I observe that I get
errors from "touch foo/" and not from "touch foo" (if foo did not
previously exist).  I observe that "mv foo bar/" fails if bar does not
exist as a directory.  All this makes me expect that a trailing slash
should be permitted on a directory name but illegal on a non-directory

I might not have non-BSD historical precedent on my side, but I surely
have the principle of least astonishment on my side.  Allowing "bar/"
to refer to a non-directory file is very astonishing to people
familiar with the way '/' is usually used in filenames.

> If you really want to get an error from a bare system call when
> you refer to a directory that does not exist then you should be
> explicit about it's property as a directory and refer to it as:  
> "bar/."

Yes, I could do that.

--apb (Alan Barrett)