Название: CompTIA Linux+ Powered by Linux Professional Institute Study Guide
Автор: Richard Blum
Издательство: John Wiley & Sons Limited
Жанр: Зарубежная образовательная литература
isbn: 9781119021223
isbn:
$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 1.1. Sometimes a single keyword has entries in multiple sections. For instance, passwd
has entries under both section 1 and section 5. In most cases, man
returns the entry in the lowest-numbered section, but you can force the issue by preceding the keyword by the section number. For instance, typing man 5 passwd returns information on the passwd
file format rather than the passwd
command.
Table 1.1 Manual sections
Some programs have moved away from man
pages to info
pages. The basic purpose of info
pages is the same as that for man
pages. However, info
pages use a hypertext format so that you can move from section to section of the documentation for a program. Type info info to learn more about this system.
There are also pages specifically for the built-in (internal) commands called the help
pages. To read the help
pages for a particular built-in command, type help command. For instance, to get help on the pwd
command, type help pwd at the shell prompt. To learn more about how to use the help
pages, type help help at the shell prompt.
The man
pages, info
pages, and help
pages are usually written in a terse style. They're intended as reference tools, not tutorials! They frequently assume basic familiarity with the command, or at least with Linux in general. For more tutorial information, you must look elsewhere, such in books or on the Web.
Using Streams, Redirection, and Pipes
Streams, redirection, and pipes are some of the more powerful command-line tools in Linux. Linux treats the input to and output from programs as a stream, which is a data entity that can be manipulated. Ordinarily, input comes from the keyboard and output goes to the screen. You can redirect these input and output streams to come from or go to other sources, such as files. Similarly, СКАЧАТЬ