7. Press the Up arrow key. You should see the ls – l three
command appear on the command line.
8. Press Ctrl+A to move the cursor to the beginning of the line.
9. Press the Right arrow key once, and type es (without pressing the Enter key). The command line should now read less – l three
.
10. Press the Right arrow key once, and press the Delete key three times. The command should now read less three
. Press the Enter key to execute the command. (Note that you can do so even though the cursor isn't at the end of the line.) This invokes the less
pager on the three
file. (The less
pager is described more fully later in “Paging through Files with less
.”) Because this file is empty, you'll see a mostly empty screen.
11. Press the Q key to exit from the less
pager.
Exploring Shell Configuration
Shells, like many Linux programs, are configured through files that hold configuration options in a plain-text format. The bash
configuration files are actually bash
shell scripts, which are described more fully in Chapter 9. A couple of examples of these configuration files are ∼/
.bashrc
and /etc/profile
.
Even without knowing much about shell scripting, you can make simple changes to these files. Edit them in your favorite text editor, and change whatever needs changing. For instance, you can add directories to the $PATH
environment variable, which takes a colon-delimited list of directories.
Be careful when changing your bash
configuration files, particularly the global bash
configuration files. Save a backup of the original file before making changes, and test your changes immediately by logging in using another virtual terminal. If you spot a problem, revert to your saved copy until you determine the problem's causes and create a working file.
Using Environment Variables
Environment variables are like variables in programming languages – they hold data to be referred to by the variable name. Environment variables differ from programs' internal variables in that they're part of the program's environment, and other programs, such as the shell, can modify this environment. Programs can rely on environment variables to set information that can apply to many different programs. For instance, many text-based programs need to know the capabilities of the terminal program you use. This information is conveyed in the $TERM
environment variable, which is likely to hold a value such as xterm
or linux
. Programs that need to position the cursor, display color text, or perform other tasks that depend on terminal-specific capabilities can customize their output based on this information.
Chapter 9 describes environment variables and their manipulation in more detail. For the moment, you should know that you can set them in bash
by using an assignment (=
) operator followed by the export
command. A fun environment variable to change is the $PS1
variable. It modifies your shell prompt:
You can combine these two commands into a single form:
Either method sets the $PS1
environment variable to a new setting. When setting an environment variable, you omit the dollar sign, but subsequent references include a dollar sign to identify the environment variable as such. Thereafter, programs that need this information can refer to the environment variable. In fact, you can do so from the shell yourself using the echo
command:
An echo
of the $PS1
variable value can be a little confusing because it just shows your current prompt setting. However, you can get a better feel for displaying an environment variable by viewing the $PATH
variable using echo
:
That's a little better. Remember, the $PATH
environment variable provides the shell with a directory list to search when you're entering command or program names.
Some environment variables, including the $PATH
environment variable, are set automatically when you log in via the shell configuration files. If a program uses environment variables, its documentation should say so.
You can also view the entire environment by typing env. The result is likely to be several dozen lines of environment variables and their values. Chapter 9 describes what many of these variables are in more detail.
To delete an environment variable, use the unset
command. The command takes the name of an environment variable (without the leading $
symbol) as an option. For instance, unset PS1 removes the $PS1
environment variable. But if you do this, you will have no shell prompt!
Getting Help
Linux provides a text-based help system known as man
. This command's name is short for manual, and its entries (its man
pages) provide succinct summaries of what a command, file, or other feature does. For instance, to learn about man
itself, you can type man man. The result is a description of the man
command.
To peruse the manual pages for a particular command or topic, you type man followed by the command or topic as an option. For example, to read about the export
command, you would type man export at the prompt. If you wanted to learn more about the shell built-in (internal) commands, you would type man builtin at the prompt.
The man
utility uses the less
pager by default to display information. This program displays text a page at a time. Press the spacebar to move forward a page, Esc followed by V to move back a page, the arrow keys to move up or down a line at a time, the slash (/) key to search for text, and so on. (Type man less to learn all the details, or consult the upcoming section “Paging through Files with less
.”) When you're done, press Q to exit less
and the man
page it's displaying.
You aren't stuck using the less
pager with the man
utility. You can change the pager by using the -P
option. For example, if you decided to use the more
pager instead to look up information on the uname
command, you would type man – P /bin/more uname at the shell prompt.
Occasionally, the problem arises where you can't remember the exact name of a command to look up. The man
utility has an option to help you here. You can use the -k
option along with a keyword or two to search through the man
pages:
The returned information (shown as a partial listing above) can give you some clues as to your desired command name. Be aware that poor keyword choices may not produce the results you seek.
On some older Linux distributions, you may get no results from a man
utility keyword search. This is most likely due to a missing whatis database. The whatis database contains a short description of each man
page, and it is necessary for keyword searches. To create it or update it, type makewhatis at the prompt. You will need to do this as superuser, and it may take several minutes to run.
Linux man
pages are organized into several sections, which are summarized in Table