Online Book Reader

Home Category

Classic Shell Scripting - Arnold Robbins [234]

By Root 822 0

The complete list of nested directories to reach a file is referred to as the pathname, or just the path. It may or may not include the filename itself, depending on context. How long can the complete path to a filename, including the name itself, be? Historical Unix documentation does not supply the answer, but POSIX defines the constant PATH_MAX to be that length, including the terminating NUL character. It requires a minimum value of 256, but the X/Open Portability Guide requires 1024. You can use the getconf command to find out the limit on your system. One of our systems gave this result:

$ getconf PATH_MAX .

What is longest pathname in current filesystem?

1023

Other Unix systems that we tried this on reported 1024 or 4095.

The ISO Standards for the C programming language call this value FILENAME_MAX, and require it to be defined in the standard header file stdio.h. We examined a dozen or so flavors of Unix, and found values of 255, 1024, and 4095. Hewlett-Packard HP-UX 10.20 and 11.23 have only 14, but their getconf reports 1023 and 1024.

Because Unix systems can support multiple filesystems, and filename length limits are a property of the filesystem, rather than the operating system, it really does not make sense for these limits to be defined by compile-time constants. High-level language programmers are therefore advised to use the pathconf( ) or fpathconf( ) library calls to obtain these limits: they require passing a pathname, or an open file descriptor, so that the particular filesystem can be identified. That is the reason why we passed the current directory (dot) to getconf in the previous example.

Unix directories are themselves files, albeit ones with special properties and restricted access. All Unix systems contain a top-level directory named bin that holds (often binary) executable programs, including many of the ones that we use in this book. The full pathname of this directory is /bin, and it rarely contains subdirectories.

Another universal top-level directory is usr, but it always contains other directories. The pathname of one of these is /usr/bin, which is distinct from /bin, although some magic, discussed later in this Appendix in Section B.4.3, can make the two bin directories look the same.[11]

All Unix directories, even if otherwise empty, contain at least two special directories: . (dot) and .. (dot dot). The first of these refers to the directory itself: we used that earlier in the getconf example. The second refers to the parent directory: thus, in /usr/bin, .. means /usr, and ../lib/libc.a means /usr/lib/libc.a, the customary location of the C programming language runtime library.

The root directory is its own parent, so /, /.., /../.., /../../.., and so on, are equivalent.

A path that ends in a slash is of necessity a directory. If the last character is not a slash, whether the last component is a directory or some other type of file can be determined only by consulting the filesystem.

POSIX requires that consecutive slashes in a path be equivalent to a single slash. This requirement is not evident in most early Unix documentation that we consulted, but the original Version 6 source code from the mid-1970s does slash reduction.[12] Thus, /tmp/x, /tmp//x, and //tmp//x are the same file.

Footnotes sprinkled through this book contain World Wide Web uniform resource locators (URLs) whose syntax is modeled on Unix pathnames. URLs prefix a protocol[13] name and a hostname in the form proto://host to an absolute Unix-like pathname rooted in the host's web directory tree. Web servers are then required to map that path to whatever is appropriate for their native filesystem. The widespread use of URLs since the late 1990s in broadcast and print media has thus made the Unix pathname familiar even to people who have never used a computer.

Layered Filesystems

If slash is the root directory, and there is one in each filesystem, how does Unix support multiple filesystems without root-directory name collisions? The answer is simple: Unix permits one filesystem to be logically

Return Main Page Previous Page Next Page

®Online Book Reader