14.2 Using Relative and Absolute PathnamesEverything in the UNIX filesystem - files, directories, devices, named pipes, and so on - has two pathnames: absolute and relative. If you know how to find those names, you'll know the best way to locate the file (or whatever) and use it. Even though pathnames are amazingly simple, they're one of the biggest problems beginners have. Studying this article carefully can save you a lot of time and frustration. See Figure 14.1 for an illustration of the UNIX filesystem. Figure 14.1: A UNIX Filesystem TreeTable 14.1 describes the two kinds of pathnames.
To make an absolute pathname:
For example, to get a listing of the directory highlighted in Figure 14.1 , no matter what your current directory is, you'd use an absolute pathname like this:
% To make a relative pathname:
For example, if your current directory is the one shown in Figure 14.1 , to get a listing of the Sub subdirectory, use a relative pathname:
% Without changing your current directory, you can use a relative pathname to read the file d in the Sub subdirectory:
% To change the current directory to Jim's home directory, you could use a relative pathname to it:
% Using the absolute pathname, /home/jim , might be easier there. The symbolic link ( 18.4 ) adds a twist to pathnames. What two absolute pathnames would read the file that the symlink points to? The answer: /home/jane/.setup or /work/setups/generic . (The second pathname points directly to the file, so it's a little more efficient.) If your current directory was the one shown in Figure 14.1 , what would be the easiest way to read that file with the more ( 25.3 ) pager? It's probably through the symlink:
% Remember, when you need to use something in the filesystem, you don't always need to use cd first. Think about using a relative or absolute pathname with the command; that'll almost always work. If you get an error message, check your pathname carefully; that's almost always the problem. If it's hard to visualize the filesystem, a program that makes a diagram of the directory tree ( 16.19 , 16.20 ) can help. - |
|