Paths

For all the newbies out there who have just acquired their first computer, here's the map for finding your way around the many paths inside it.
Starting at Home

After logging in, type pwd at your Linux prompt, and you will see something like this:

/home/williams

This is a path; in this case, the path for my home directory. A directory is where files are kept. They can also contain other directories. The path /home/williams is shorthand for “The directory williams which is in the directory home, local, which is in the root directory of the file system.” Each word between / characters is a name; what it names is a directory. The pwd command reported /home/williams to me, because it was my “Present Working Directory,” more commonly known as the current or default directory.

The current directory is a simple idea with many faces. Immediately after logging in, it is your home directory. Later, it could be any directory on your file system. Your current directory is really that of your shell. Other processes have their own, which change independently. A single process with multiple sub-windows may even maintain a current directory for each.

It is useful to be aware that a command-line user will say “I am in /etc/skel”, while a graphical interface user of the same system would report that /etc/skel is “open”. Both mean the same thing. The current directory is the assumed target of your commands and any files requested. Paths let you refer to other directories. Unfortunately, learning to use them can be needlessly painful due to the historical choice of nomenclature.

Puzzling Nomenclature

Nomenclature describes how things are named. The / symbol, in path names, suffers from a nomenclature quirk known as overloading, which means it can be correctly interpreted in more than one way.

If a path begins with /, the meaning is “the root”. The root is itself a directory. [Note that /, meaning the root directory of the file system, should not be confused with /root, a directory in the / directory—Ed] Think of it as the boss directory which isn't contained by any other. Beginners often fail to “see” root at all, because the visual impact of a leading / is small. This is a serious error. A / between two directory names, after root, merely separates them. The / is not a directory—it is just a delimiter. Try this simple test to see if you've got it. How many directories are there in /home/williams?

The answer is three, not two. The two most first-year students in my course get are /home and /home/williams. About a quarter every term fail to count the root itself. If we step beyond paths to files, the nomenclature becomes ambiguous. No matter how closely we inspect /home/williams/foo, we cannot deduce whether foo is a file or a directory. If the name were /home/williams/foo.txt, we might believe foo.txt is a file, but it is possible for directories to have extensions, and common for files to omit them.

What do the following two examples tell you about the names lists and weba? (The cd [Change Directory] command resets your current directory.)

Example 1
$ cd /home/lynda/lists
$ pwd
/home/lynda/lists
Example 2
$ cd /home/lynda/weba
bash: /home/lynda/weba: Not a directory
$ pwd
/home/ftp/pub/weba

You should be able to deduce that lists is a directory, but weba isn't. Of course, there are plenty of ways, starting with past experience, to resolve ambiguity. The file command is another, as are the -F and -l options for the ls command.

Relative paths

So far, all my paths have begun with the root. Path names which begin this way have the same meaning no matter what the current directory is. They are called absolute paths. For example, the command:

$ cd /home/ftp/pub/weba

will make /home/ftp/pub/weba my new current directory regardless of the existing one. What would the command below achieve?

$ cd weba
Any reference to a file or directory which does not begin with a slash (/) is relative. This begs the question “relative to what?” Relative to the current directory. The command above, therefore, will work as desired only if my current directory is already /home/ftp/pub. Consider the following attempts to use relative paths to change directories. The prompt has changed to show the current directory before the $ symbol, and I have taken liberties with spacing to enhance readability.
Example 1 (success)
/home $ cd ftp/pub
/home/ftp/pub $
Example 2 (failure)
/home $ cd pub
bash: pub: No such file or directory
/home $
example 3 (failure)
/home $ cd /ftp/pub
bash: /ftp/pub: No such file or directory
/home $
example 4 (success)
/home $ cd ..
/ $
Relative paths are just absolute paths with the current directory assumed as a prefix. They are more common than absolute ones, as we tend to work out of the directory of greatest interest to us at the moment. Note, however, that it is wrong to start one with a /, as in example 3, because doing so makes the path absolute. Sticklers for syntax will note we lose a delimiter / in the bargain.

Two special components in building relative paths, are . and .. which stand for “this directory” and “the directory containing this directory ”, respectively. You can use them alone, as in example 4, or with other components as in this fairly typical example of backing up and going forward to a different directory:

/home/ftp $     cd ../williams
/home/williams $
______________________

Webcast
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers

Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.

Learn More

Sponsored by AMD

White Paper
Red Hat White Paper: Using an Open Source Framework to Catch the Bad Guy

Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6

Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.

Learn more about catching the bad guy in this free white paper.

Learn More

Sponsored by DLT Solutions