| UNIX Tutorial | 3. Looking around | ||||||||||||||||||||||||
|
Commands covered in this section: pwd, ls, cd Like other operating systems, UNIX organizes user data, programs, etc. into structures called files. Files, in turn, are placed in directories (referred to as "folders" in some operating systems). Directories are organized into a hierarchical structure, something like an upside down tree. This entire structure, including all of the directories and files, as well as the special structures the operating system uses to keep track of them, is called a filesystem. A simplified UNIX filesystem is shown in Figure 3.1. Figure 3.1 A UNIX filesystem.
As you use UNIX, the shell keeps track of your current location within the filesystem. This is called the working directory . The pwd ("print working directory") command tells you where you are in the filesystem by printing the current working directory. Let's give it a try. Exercise 3.1
Enter the pwd command at the shell prompt.
When you log in, UNIX initially sets your working directory to
your home directory. This is a special location where
you store your personal data as well as the configuration files
that govern your account. Since you've just logged in and haven't
yet learned how to change directories, what you see when you enter
the pwd command is your home directory. Naming the
home directory after the user and placing it under a directory
called "/home" (as in our example) is a sensible convention, but
it's not a strict rule. You may find that the name of your home
directory is somewhat different.
The location of a file or directory within the filesystem is called a pathname, because it describes the path you must follow to find it. You can construct a pathname by starting at the root directory and working your way down. Each level in the hierarchy is separated by the "/" character. For example, you will notice that there is a directory called home underneath the root directory in Figure 3.1, and underneath that is another directory called natasha. The absolute pathname for the natasha directory would be /home/natasha (the first "/" character represents the root directory; the second separates "home" from "natasha"). This type of pathname is called an absolute pathname because it starts from a fixed reference point, the root directory ("/"). A relative pathname, on the other hand, describes the location of a file in relation to the current working directory. If the current working directory were /home, the relative pathname for accessing the natasha directory would simply be natasha. To change the current working directory, use the cd command followed by the pathname of the desired directory. Exercise 3.2 Use the cd command to move to the directory just above your home directory.In exercise above you used an absolute pathname ("/home") to move to the directory above your home directory. You could also have used a relative pathname. The directory above the current working directory, known as the parent directory, is identified by a special notation: ".." (two period characters). Exercise 3.3 Use the cd command to move up one level in the directory tree.Now that you know where your home directory is, perhaps you'd like to know what files and directories are stored in it. You list files and directories with the ls command. Exercise 3.4 Enter the ls command at the shell prompt.The "-F" option causes ls to produce a "fancy" listing. A special character, appended to the filename, is used to identify certain types of files (see table 3.1). Regular files remain unadorned. Some system administrators create an alias which causes the "-F" option to be added to the ls command automatically. If this is the case on your system, you will see the fancy listing without having to include "-F". Table 3.1 The ls command is a bit reticent; it won't actually tell you about all your files unless you explicitly ask it to do so via the "-a" option. Exercise 3.5
Enter the ls command with the "-a" and "-F" options.
Several new files showed up this time. "./" represents the current
directory and "../" represents the parent directory. The other files
beginning with "." are configuration files that control the behavior
of various programs (for example, .cshrc and .login are used by
csh).
You can get more information about files you are listing by using the "-l" option with ls. Exercise 3.6
Enter the ls command with the "-a", "-l", and "-F"
options.
The long listing generated by adding the "-l" option to ls
produces information in seven columns as described in Table 3.2.
Table 3.2
|
|||||||||||||||||||||||||
|
< previous | table of contents | next > |
|||||||||||||||||||||||||