If you are setting your prompt temporarily by typing at the shell, you should put the value of PS1
in quotes. For example, you could type export PS1="[\t \w]\$ "to see a prompt that looks like this:
[20:26:32 /var/spool]$.
To make a change to your prompt permanent, add the value of PS1
to your .bashrc
file in your home directory (assuming that you are using the bash shell). There may already be a PS1
value in that file, which you can modify. Refer to the Bash Prompt HOWTO
( http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO
) for information on changing colors, commands, and other features of your bash shell prompt.
Adding environment variables
You might want to consider adding a few environment variables to your .bashrc
file. These can help make working with the shell more efficient and effective:
TMOUT This sets how long the shell can be inactive before bash automatically exits. The value is the number of seconds for which the shell has not received input. This can be a nice security feature, in case you leave your desk while you are still logged in to Linux. To prevent being logged off while you are working, you may want to set the value to something like TMOUT=1800 (to allow 30 minutes of idle time). You can use any Terminal session to close the current shell after a set number of seconds, for example, TMOUT=30.
PATH As described earlier, the PATH variable sets the directories that are searched for the commands that you use. If you often use directories of commands that are not in your path, you can permanently add them. To do this, add a PATH variable to your .bashrc file. For example, to add a directory called /getstuff/bin, add the following: PATH=$PATH:/getstuff/bin ; export PATHThis example first reads all of the current path directories into the new PATH ($PATH), adds the /getstuff/bin directory, and then exports the new PATH.CAUTIONSome people add the current directory to their PATH by adding a directory identified simply as a dot (.), as follows: PATH=.:$PATH ; export PATHThis enables you to run commands in your current directory before evaluating any other command in the path (which people may be used to if they have used DOS). However, the security risk with this procedure is that you could be in a directory that contains a command that you don't intend to run from that directory. For example, a malicious person could put an ls command in a directory that, instead of listing the content of your directory, does something devious. Because of this, the practice of adding the dot to your path is highly discouraged.
WHATEVER You can create your own environment variables to provide shortcuts in your work. Choose any name that is not being used and assign a useful value to it. For example, if you do lots of work with files in the /work/time/files/info/memos directory, you could set the following variable: M=/work/time/files/info/memos ; export MYou could make that your current directory by typing cd $M. You could run a program from that directory called hotdog by typing $M/hotdog. You could edit a file from there called bun by typing vi $M/bun.
Getting Information about Commands
When you first start using the shell, it can be intimidating. All that you see is a prompt. How do you know which commands are available, which options they use, or how to use advanced features? Fortunately, lots of help is available. Here are some places that you can look to supplement what you learn in this chapter:
Check the PATH. Type echo $PATH. You see a list of the directories containing commands that are immediately accessible to you. Listing the contents of those directories displays most standard Linux commands. For example:$ ls /bin arch dd fusermount loadkeys mv awk df gawk login nano basename dmesg gettext ls netstat bash dnsdomainname grep lsblk nice cat domainname gtar lscgroup nisdomainname chgrp echo gunzip lssubsys ping chmod ed gzip mail ping6 chown egrep hostname mailx ps cp env ipcalc mkdir pwd cpio ex kbd_mode mknod readlink csh false keyctl mktemp red cut fgrep kill more redhat_lsb_init dash find link mount rm date findmnt ln mountpoint rmdir
Use the help command. Some commands are built into the shell, so they do not appear in a directory. The help command lists those commands and shows options available with each of them. (Enter help | less to page through the list.) For help with a particular built-in command, enter help command, replacing command with the name that interests you. The help command works with the bash shell only.
Use --help with the command. Many commands include a --help option that you can use to get information about how the command is used. For example, if you enter date --help | less, the output shows not only options, but also time formats that you can use with the date command. Other commands simply use a –h option, like fdisk -h.
Use the info command. The info command is another tool for displaying information about commands from the shell. The info command can move among a hierarchy of nodes to find information about commands and other items. Not all commands have information available in the info database, but sometimes more information can be found there than on a man page.
Use the man command. To learn more about a particular command, enter man command. (Replace command with the command name you want.) A description of the command and its options appears on the screen.
Man pages are the most common means of getting information about commands as well as other basic components of a Linux system. Each man page falls into one of the categories listed in Table 3.8. As a regular user, you will be most interested in man pages in section 1. As a system administrator, you will also be interested in sections 5 and 8, and occasionally section 4. Programmers will be interested in section 2 and 3 man pages.
TABLE 3.8 Manual Page Sections
Section Number |
Section Name |
Description |
1 |
User Commands |
Commands that can be run from the shell by a regular user (typically no administrative privilege is needed) |
2 |
System Calls |
Programming functions used within an application to make calls to the kernel |
3 |
C Library Functions |
Programming functions that provide interfaces to specific programming libraries (such as those for certain graphical interfaces or other libraries that operate in user space) |
4 |
Devices and Special Files |
Filesystem nodes that represent hardware devices (such as Terminals or CD drives) or software devices (such as random number generators) |
5 |
File Formats and Conventions |
Types of files (such as a graphics or word processing file) or specific configuration files (such as the passwd or group file) |
6 |
Games |
Games available on the system |
7 |
Miscellaneous |
Overviews of topics such as protocols, filesystems, character set standards, and so on |
8 |
System Administration Tools and Daemons |
Commands that require root or other administrative privileges to use |
Options to the man
command enable you to search the man page database or display man pages on the screen. Here are some examples of man commands and options:
$ man -k passwd … passwd (1) - update user's authentication tokens passwd (5) - password file $ man passwd $ man 5 passwd
Using the -k
option, you can search the name and summary sections of all man pages installed on the system. There are about a dozen man pages that include “ passwd
” in the name or description of a command.
Читать дальше