My question is about whether I should think about these as synonyms for relative or absolute pathnames
I would suggest to skip this stage and go straight to thinking about these just like any other directory, because that is what they are in all manners relevant to you (unless you are a kernel or filesystem-module developer).
Gilles' answer is fine and well, and I see no particular wrong information in it.
That said: it is absolutely possible and useful to view "." and ".." as bog-standard directories. Whatever you do with them in scripts or applications works just like they were directories (and as Gilles says, in some past they actually were).
Most importantly: you have to keep the concept of an inode separate from that of a directory entry in your head. An inode describes where "something" is stored in the file system (in a quite physical manner, i.e. the very disk blocks). The directory entry is a more abstract representation containing a human-readable name, the corresponding inode, attributes, dates and such.
A directory itself can be fined like an internally handled file which has some representation for listing those entries (this is simplified of course). The important bit is that the actual storage is very separated from where the info about where it's stored.
If I type the following, I can see the inodes of those directories (first column):
~/tmp$ ls -ilaO
total 8
16326296 drwxr-xr-x 8 me staff - 256 Jan 15 14:02 .
1129613 drwxr-xr-x+ 112 me staff - 3584 Jan 19 17:25 ..
16326815 drwxr-xr-x 2 me staff - 64 Jul 27 2020 a_directory
126333718 -rw-r--r-- 1 me staff - 0 Jan 15 14:07 a_file
Going "upstairs", I can check how tmp
is represented in its parent directory:
~$ ls -ilaO -d tmp
16326296 drwxr-xr-x 8 me staff - 256 Jan 15 14:02 tmp
tmp
in the parent directory points to the same inode as .
inside tmp
, as expected.
Checking the .
of the parent directory:
~$ ls -ilaO -d .
1129613 drwxr-xr-x+ 112 me staff - 3584 Jan 19 17:25 .
reveals that the inode of .
in the parent is the same as the inode of the ..
entry in the child directory, as expected.
I can use .
and ..
in almost all places where I could use the name of every other directory in the system. If there is a difference at all, this is because the command I am using has special logic implemented for some reason (for example for security reasons - a web server could enforce that a path can never contain ..
so someone cannot "escape" a security rule and type in an URL like http://domain/index.html/../../../../etc/passwd to get the password file).
Other programs (like bash
) might have some kind of magic handle ".." special. For example, when I do a cd ..
the bash knows that my current path is not /where/i/was/before/..
but just /where/i/was
. This answers your question about how to think about the shell: you can imagine that it just does what it thinks you want to achieve, to make it easier for you. Other programs which have no special logic for ..
can usually and easily work with ..
anywhere in their paths, and will be blithely unaware of them - everything will just work fine since ..
is a path name just like any other path name.
cd
: How is..
(dot dot) resolved in bash when cwd is a symlink to a directory. – Kamil Maciorowski Jan 24 '24 at 18:34..
looks obviously a relative path, just like e.g.foo.txt
does. Neither can be resolved without context, the current working directory. But, since you ask "is relative pathnaming a special case of absolute pathnaming" and I wonder, what would the difference be? What would be different if it was a special case of the other, vs. if it was not a special case but something completely separate? – ilkkachu Jan 24 '24 at 18:49