/..
points to /
:
$ ls -id /
2 /
$ ls -id /..
2 /..
Both have the same inode number, which happens to be 2 on this system. (The exact value doesn't matter.)
It's done for consistency. This way, there doesn't have to be code in the kernel to check where it currently is when it processes a ..
in a path. You can say cd ..
forever, and never go deeper than the root.
I don't believe that there is any way to determine whether a filesystem is remote or local using only POSIX interfaces. POSIX doesn't even mandate a mount
command, and all references to file systems, as far as I know, are replete with the words "implementation-defined".
The -local
primary to the find
command is not much help, since it is only available on Solaris, and it depends on the existence of a configuration file which lists remote filesystem types.
POSIX does mandate a df
command and requires a specific output format if that command is used with the -P
flag; in that format, there are six space-separated fields, of which the first is the "name of the file system, in an implementation-defined format" and the last is the mount point.
What you need is a list of all the mount points corresponding to local filesystems. Here, I think you're going to have to fall back to a heuristic; which is to exclude filesystem names which "look like" remote filesystems. Some examples:
//... CIFS (Samba)
host:... NFS
/afs AFS
That's not an exhaustive list, and it comes completely without guarantees.
If you then filter those lines out of the output of df
and then remove the first five columns, you could then feed the list to the find
command with the -xdev
primary.
Even if that sounds plausible, there is actually no guarantee that a filesystem is actually "mounted" (see AFS) or that a filesystem is either entirely local or entirely remote (a fuse-based filesystem can arbitrarily redirect individual files). So proceed with caution, is my advice.
Best Answer
According to The Open Group's published standard, the only required directories are:
/
/dev
, which containsconsole
,null
, andtty
/tmp
, guaranteed writable but not necessarily preserved.The Linux Foundation maintains a Filesystem Hierarchy Standard (FHS) which extends this to include the directories you will typically see on a Linux system:
The FHS was designed to be as generic as possible, to allow for incorporation in any UNIX system. The additional directories are likely to exist in any reasonable system, but this is not mandated by POSIX.
However, note that The Open Group also states that
Since directories are really just files, this implies that a strictly conforming application will not create any files or directories at the root level. Therefore, POSIX does not necessarily limit what a distribution may place at the root level, but does seem to state that an application conforming to its specification cannot assume that it will be able to.