4.1.1.1. Understanding the shell prompt
[chris@concord2 ~]$
This message is an invitation to enter a command. It shows the name of the user ( chris ), the computer being used ( concord2 ), and the current working directory within the filesystem ( ~ , meaning the user's home directory). The last character of the prompt, $ , indicates that this is a normal user's prompt, as opposed to the system administrator's prompt, which ends with # .
4.1.1.2. Entering commands
To edit a command line, use the left and right arrow keys to position within the line, and the Backspace and Delete keys to delete characters to the left or right of the cursor, respectively. To insert text, simply type it. You can press Enter with the cursor located anywhere on the line to execute the command. Other editing keys are available; Table 4-1 shows the most useful ones.
Table 4-1. Useful editing keys
| Key or key sequence | Description |
|---|---|
| Left arrow | Move left one character. |
| Right arrow | Move right one character. |
| Backspace | Delete the character to the left of the cursor. |
| Delete | Delete the character under/to the right of the cursor. |
| Ctrl-U | Delete to the start of the line. |
| Ctrl-left arrow | Move one word to the left. |
| Ctrl-right arrow | Move one word to the right. |
| Esc, DAlt-D | Delete to the end of the current word. |
| Esc, BackspaceAlt-Backspace | Delete to the start of the current word. |
| HomeCtrl-A | Go to the start of the line. |
| EndCtrl-E | Go to the end of the line. |
4.1.1.3. Accessing previous commands
You can also search for a previous command by pressing Ctrl-R (for reverse search ) and then typing a few characters that appear in the command. For example, if you had at some previous point typed cat /etc/hosts and you pressed Ctrl-R and typed hos , the cat /etc/hosts command would appear (providing that no intervening commands contained the letter sequence hos ).
4.1.1.4. Obtaining a root prompt to enter commands as the superuser
root root root rootAlthough you can directly log in as a root user, it's usually much safer to take on root privilege only when necessary, using the su (switch user) command:
$ su
Password:
root-password
#
The shell prompt will change to end in a pound sign ( # ) instead of a dollar sign ( $ ) when you are in root mode. Press Ctrl-D or type exit to drop superuser access and return to your regular shell prompt.
In this book, I'll use $to indicate any normal user's prompt, user $to specifically indicate user 's prompt, and # to indicate the root prompt. Avoid entering commands as root unnecessarily!
4.1.1.5. Linux error messages
rm$ rm barbeque
rm: cannot remove \Qbarbeque ': No such file or directory
Most error messages start with the name of the command that produced the message.
4.1.1.6. Logging out of a shell prompt
4.1.2. How Does It Work?
bash bash sh bashWhen bash receives a command, it splits it into words and uses globbing to expand any ambiguous filenames. bash next checks to see if the first word is a built-in command. If not, it treats it as an external command or program and searches a list of directories to find that program. It executes that program, passing the other words to the program as arguments. Almost all Linux commands are external programs.
Linux commands generally accept three types of arguments:
The output will appear as shown in Figure 4-1 . You can use the up and down arrow keys and the Page Up/Page Down keys to scroll through the text, or q to quit. You can also type / , enter some text, and press Enter to search for that text within the document; type n (lowercase n , for next ) to search again. ? and N (uppercase N ) can be used in the same way to search backwards.
Figure 4-1. Online display of a manpage
To request a manpage from a specific section of the manual, give the section as the first argument and the name of the manpage as the second argument:
$ man2 uname
If you don't specify the section, the first section containing a page with the requested name is usedand since there is a uname page in section 1, you won't see the page from section 2 unless you specifically ask for it.
4.2.1.2. Finding a manpage
calendar$ man -k calendar
Date::Calc (3pm) - Gregorian calendar date calculations
Date::Calendar (3pm) - Calendar objects for different holiday schemes
Date::Calendar::Profiles (3pm) - Some sample profiles for Date::Calendar and
Date::Calendar::Year
Date::Calendar::Year (3pm) - Implements embedded year objects for Date::Calendar
cal (1) - displays a calendar
Note that the section number is in parentheses. If you were looking for a calendar command, you could ignore the results from section 3 of the manual (library functions), which leaves just one possibility: the cal command. You could then get more information about that command to see if it will do what you need :
$ mancal
apropos is another name for man -k. To my ear, it has more class!
$ whatisuname
uname (1) - print system information
uname (2) - get name and information about current kernel
In this case, you can see that there is a page for uname in section 1 and 2 of the manual.