2.16.1 Unix Pathnames

Unix pathnames are always parsed with a unix-host object as the host and nil as the device. The last two dots (.) in the namestring mark the type and version, however if the first character is a dot, it is considered part of the name. If the last character is a dot, then the pathname has the empty-string as its type. The type defaults to nil and the version defaults to :newest.

Emacs-style versioning is also supported, as shown below for “foo.bar.~1~”.

(defun parse (x)
  (values (pathname-name x) (pathname-type x) (pathname-version x)))

(parse "foo") ⇒ "foo", NIL, NIL
(parse "foo.bar") ⇒ "foo", "bar", NIL
(parse ".foo") ⇒ ".foo", NIL, NIL
(parse ".foo.bar") ⇒ ".foo", "bar", NIL
(parse "..") ⇒ NIL, NIL, NIL
(parse "foo.") ⇒ "foo", "", NIL
(parse "foo.bar.~1~") ⇒ "foo", "bar", 1
(parse "foo.bar.baz") ⇒ "foo.bar", "baz", NIL

The directory component of pathnames beginning with a slash (or a search-list, see search-lists) starts with :absolute, others start with :relative. The .. directory is parsed as :up; there is no namestring for :back:

(pathname-directory "/usr/foo/bar.baz") ⇒ (:ABSOLUTE "usr" "foo")
(pathname-directory "../foo/bar.baz") ⇒ (:RELATIVE :UP "foo")

Tilde expansion is also supported in pathnames. Thus “~/” is expanded to the current user’s home directory, and “~name/” expands to home directory of the user whose login id is “name”. The trailing “/” is required to specify a directory. Without it, the parser interprets it as a filename starting with a “~”.

(pathname "~/") ⇒ #P"/home/user/"
(pathname "~games/") ⇒ #P"/usr/games/"
(pathname "~bin/sh") ⇒ #P"/bin/sh"
(pathname "~games") ⇒ #P"~games"
(pathname-name (pathname "~games")) ⇒ "~games"
(truename "~games") ⇒ File-error; the file "~games" does not exist