frag_l_0000001



This documentation fragment is yet another illustrated summary, how to view the Linux file paths so that the coding effort is minimized. The illustrative images are built by using Graphviz. The approach is similar to regular expressions, where there is a model and a notation is mapped to the model.

The Model and the Notation




Explanation by an example:






The model is that there are containers that contain elements that can be, but do not have to be, other containers, and every element has a name that is unique within the container that the element resides in and every element has a type attribute and set of type specific, optional, attributes.



Observations



The code of a bit more elaborate illustration:

digraph file_system_example {
"/" -> "a/" -> "d/";
"/" -> "dev/" -> "sda";
"/" -> "symlink_2";
"/" -> "e/";
"a/" -> "b/" -> "c/"
"b/" -> "e/ "; /* The space is a hack, not part of the vertex ID. */
"c/" -> "hello.txt"
"c/" -> "symlink_1"
}














Folder as a container is marked by slash-suffix . An element of a container is designated by omitting the slash-suffix. The slash-suffixed path can be seen as a path to a "virtual file" that designates a set of container elements that form the whole content of the container.

Symlink is just a special purpose file, a bit like device files and named pipes, regardless of its state or referenced object.

Upwards traversal is designated by a doubledot (..) . Upwards traversal above root

/tmp/foo/../../../../../../../../../../../bar

is interpreted as starting from root

/bar

Triple-dots (...) are illegal by Linux or Bash implementation.

Absolute paths are relative paths with the working directory of /
To distinguish absolute pats from the rest of the relative paths, the absolute paths always start with the slash and the rest of the relative paths never start with the slash. For example, if the working directory were /a/b, then without that rule the /e and /a/b/e would be indistinguishable from each other.

Tilde (~) is one possible prefix of an absolute path, but the tilde (~) can be used like any other character in file names and folder names. Text editors like the Vim use tilde as a suffix to some of its temporary files. A path candidate like

xxxx~foo

is a valid relative path.



Some Path Normalization Rules


Table of Equivalent cases
/a//////b//c////// /a/b/c/
././././././ ./
./../ ../
/a/./b/./ /a/b/
./a/ a/
./ .
../ ..
./foo/../bar ./bar
/../../ /
~/../foo /home/foo
~/../../foo /foo


As file names that consist of only spaces are valid, allowed, file paths must not be trimmed.



Hints for Details


The Single Unix Specification contains the root folder related naming inconsistency in its utility called basename .

xxxxcd /; pwd | xargs basename