|Red Hat Enterprise Linux 4: Red Hat Enterprise Linux Step By Step Guide|
|Prev||Chapter 4. Shell Prompt Basics||Next|
This chapter starts by introducing some general information about working with the command line. From there, it explains how to: locate yourself in the file system, move and manipulate files, browse to other directories, and view their contents. Finally, it moves on to more complicated issues including re-direction and permissions.
Below are a few terms to know before beginning the discussion of the shell prompt.
The command line is where options to a command are placed. The following is an example of a command line:
command -options <filename>
The shell prompt is the marker on the screen that shows where the command line should be placed. The following is an example of a shell prompt:
The shell is the program that interprets commands so that the operating system can understand them.
The terminal window is the window that contains the shell prompt, command line, and output from the shell.
Recall from Section 1.5 Opening a Shell Prompt that a terminal window is opened from the Applications (the main menu on the panel), or by right-clicking on the desktop and selecting Open Terminal.
Entering or running a command refers to typing a given
command and pressing
The shell prompt within a terminal window looks something like this:
There are any number of symbols that can be used to indicate the end of the shell prompt, and you can customize what your prompt looks like. However, there are two symbols that you will see more often than any others, "$" and "#". The first symbol, "$", is the last character in the prompt when you are logged in as a normal user. The shell prompt for a normal user looks something like this:
The second symbol, "#", is the last character in the prompt when you are logged in as root. This is true whether you logged in as root from the initial screen or if you executed the su - command to become root. The shell prompt for root looks something like this:
This slight difference can help remind you what privileges you currently have.
In general, a command run from the shell prompt will have the following format:
command -options <filename>.
Both -options and <filename> are optional: the command may not require either one, or it may require multiple options and files. When specifying multiple options, list them as a group. For example, to see a long listing of information (-l) about all files (-a) in a directory, you would run the command:
There are many variations in required information types for individual commands. If you aren't sure about a command and how it is used, you can do one of three things:
Enter the command alone at a shell prompt and press
Enter man command at a shell
prompt. This opens the manual
page for that command. A man page is a
manual written by the command's developer explaining how
it is used and what each option means. You can also
enter man man at a shell prompt
for more information on man pages. Navigate through the
man page using the directional keys on your keyboard.
Enter info command at a shell prompt. Some info pages have the same information as man pages, but navigation is slightly different. For more information, enter info info at a shell prompt.
Below are a few useful features of the bash shell that reduce the amount of typing required at a shell prompt. The first of these is tab completion, the second is command history, and the third is useful keystrokes.
Tab completion is one of the most useful shortcuts available
at the command line. Red Hat Enterprise Linux has the ability to
"guess" what command, directory, or filename you
are entering at the shell prompt. Press the
If there are multiple solutions to the partial text on the
command line, the shell presents them as a list. If the
list is very long, the shell will first ask if you would
like to display all matches. Navigate long lists of
potential matches by pressing the
The shell assumes that the first word entered at the prompt is a command. The possible completions it offers are the names of commands or applications. This can be helpful if you are not sure of the exact spelling of a command or if you are searching for a certain command. It can also serve to help a new user become familiar with the available commands.
Type the letter g at a prompt and
The shell asks if you want to see all 379 possibilities. This means that there are 379 commands that start with the letter "g". Searching through this list would take too much time.
Entering more of the command name will produce a shorter
list of possible matches. For this example, type
gnome and press
To finish entering a command with tab completion, enter
just a few more characters, "-ca", and press
Tab completion also works on filenames and directories. The
shell prompt assumes that the second word on the command
line is a filename or directory. Typing a partial word and pressing
For example, reaching the sub-directory
would take a great deal of repetitive typing. However, with tab completion, a user would only have to enter a few keystrokes:
$ cd ex
It is unnecessary to type the same command over and over. The
bash shell remembers your past commands. These commands
are stored in the .bash_history file in
each user's home directory. To use the history, press
the up arrow to scroll backward through the commands you have
already entered. The
Commands that you only typed partially and did not
By default, Red Hat Enterprise Linux stores 1000 commands. Each terminal window or shell prompt stores a separate set of commands. If you gain root privileges by using the command su -, the history file (and thus the commands) you access are root's, not the user's.
Applications and processes can be started from the command line. When an application starts from the command line, that particular shell is taken up with standard output for that application until the application closes. The screen fills with gibberish or messages that can be ignored. To continue to use the current shell while running an application from the same shell, add the ampersand, "&", to the end of the command line. For example, oowriter & starts OpenOffice.org Writer and allows you to continue entering commands on the command line. This is known as running a process in the background.
If you have started an application or process and forgotten
to add the &, first press
Wildcards are place holders used to allow users to search for or use multiple files with similar names. The subject of wildcards is part of the larger subject of regular expressions. Two of the most common wildcards are "*" and "?".
The asterisk, "*", represents any character or string of characters. The entry a*.txt could refer to ab.txt as well as aardvark.txt.
The question mark represents a single character. The entry a?.txt could refer to ab.txt and a1.txt, but not aardvark.txt.
What if you forget the name of the file you are looking for? Using wildcards or regular expressions, you can perform actions on a file or files without knowing the complete file name. Type out what you know, substituting a wildcard for the remainder.
To read more about wildcards and regular expressions, take a look at the bash man page (man bash). You can save the file to a text file by typing man bash | col -b > bash.txt. Then, you can open and read the file with less or with an editor such as vi (vi bash.txt). If you want to print the file, be aware that it is quite long.
For example, to find a file called "sneaksomething.txt," enter:
The shell lists every file that matches that pattern:
Regular expressions are more complex than the straightforward asterisk or question mark.
When an asterisk, for example, just happens to be part of a file name, as might be the case if the file sneakers.txt was called sneak*.txt, that is when regular expressions can be useful.
Using the backslash (\), you can specify that you do not want to search out everything by using the asterisk, but you are instead looking for a file with an asterisk in the name.
If the file is called sneak*.txt, type:
Here is a brief list of wildcards and regular expressions:
* — Matches all characters
? — Matches one character
\* — Matches the * character
\? — Matches the ? character
\) — Matches the ) character
While working from the command line, there are a few useful keystrokes that can help you with your session.
The following keystrokes are useful shortcuts at a shell prompt.
|While editing a command on the command line, this key combination deletes everything that has been typed in from the cursor's current position forward.|
|Pressing this key combination once ends the current application or process. Pressing it twice exits the shell.|
|At the command line,
|Suspends the current application. Entering
|"Kills" a program. This should be a last resort. Try stopping a program with other methods first.|
|Clears the terminal window.|
Table 4-1. Useful shell prompt keystrokes
The terminal window begins to look crowded very quickly. You can always exit from the terminal window and open a new one, but there is a quicker and easier way to remove the contents displayed in the terminal.
To clear the terminal, enter the command clear at the shell prompt. The clear command clears the terminal, leaving only a new shell prompt at the top of the window.
You can also clear the screen using the keystroke
Sometimes, you may accidentally open a program file or some other non-text file in a terminal window. When you close the file, you could find that the text you are typing does not match the output on the monitor.
In such cases, enter reset to return the terminal window to its default values.