When you say that a file is "in a directory," what does that really mean? It means that the file's name is listed in a special kind of file called a directory file. On traditional filesystems, at least, a directory holds a series of filenames and i-numbers. Here's a simplified picture of what our /home directory file could contain:

.     3335
..    264
root  4261
al    13256
jo    43600
fox   50133

People use the names to locate a file. Deep down, though, Linux uses the i-numbers. If your current directory is /home and you type the command cd al, Linux sees that al is a relative pathname (no slash at the start), so it checks the current directory for an entry named al. As you can see, that's i-number 13256. So Linux opens the inode (filesystem index node) with i-number 13256 and locates the actual al directory on the disk.

   Notice the special entries named . and ... Every directory has those entries. The . is a link to the current directory, and .. is a link to the parent directory (the directory that contains this directory). So, for instance, if you type cd .., Linux opens the directory at i-number 264.

   "So," you might ask, "if the root directory has i-number 264, what's that entry named root?" The answer is that the directory named root, here with i-number 4261, is the home directory for the user named root, the superuser. Its absolute pathname is /home/root -- very different than the root directory, with absolute pathname /.

   Note that our current directory is named home, but you can't tell that from looking at the directory entries. Where is its name? A directory's name is kept in its parent directory! But all directories have a link named ., which is a handy way to refer to the current directory -- from the find program, for instance.

©Linux Magazine

Author: Jerry Peek

Valid HTML 4.01!

Valid W3C_CSS