[ Team LiB ] |
7.1 Issuing Shell CommandsThe most common way to access the shell is via a terminal window, as explained in Chapter 5 and Chapter 6. However, a terminal window isn't the only way to access the shell. Section 4.3.3.2 explains how to access the shell by using a virtual console. As your first Linux command, launch a terminal window, type w, and press Enter. Your contents of the terminal window should look something like this: [bill@home bill]$ w 11:12am up 6 min, 1 user, load average: 0.00, 0.08, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT bill tty1 11:11am 0.00s 0.20s 0.11s -bash The w command tells Linux to display the system status and a list of all system users. In the example, the output of the command tells you that it's now 11:12 a.m., that the system has been up for six minutes, and that only one user—bill—is currently logged in. Notice that the command output is very terse, packing much information into a few lines. Such output is typical of Linux commands. At first, you may find Linux output cryptic and difficult to read, but over time you'll grow to appreciate the efficiency with which Linux communicates information.
Linux provides many commands besides the w command—so many that you may despair of learning and recalling them. Actually, the number of commands you'll use regularly is fairly small. Soon, they will become second nature to you. Try a second command, the date command: [bill@home bill]$ date Fri Oct 5 11:15:20 PST 2002 The date command displays the current date and time. If you find working with MS-DOS distasteful or intimidating, you may not immediately enjoy working with the Linux command line. However, give yourself some time to adjust. The Linux command line has several features that make it easier to use, and more powerful, than MS-DOS. 7.1.1 Correcting CommandsSometimes you may type a command incorrectly, causing Linux to display an error message. For example, suppose you typed dat instead of date: [bill@home bill]$ dat bash: dat: command not found In such a case, carefully check the spelling of the command and try again. If you notice an error before pressing Enter, you can use the Backspace or Left arrow key to return to the point of the error and then type the correct characters. The Backspace key erases characters whereas the Left arrow key does not. You can also use the Del key to delete unwanted characters. Just as a web browser keeps track of recently visited sites, the bash shell keeps track of recently issued commands in what's known as the history list. You can scroll back through bash's history by using the Up arrow key, or back down using the Down arrow key, just as you would with the Back and Forward buttons on a web browser. To reissue a command, scroll to it and press Enter. If you like, you can modify the command before reissuing it. When typing shell commands, you have access to a minieditor that resembles the DOSKEY editor of MS-DOS. This minieditor lets you revise command lines by typing key commands. Table 7-1 summarizes some useful key commands interpreted by the shell. The key commands let you access a list of the 500 most recently executed commands. bash's history is saved in the ~/.bash_history file.
One of the most useful editing keystrokes, Tab, can also be used when typing a command. If you type the first part of a filename and press Tab, the shell will attempt to locate files with names matching the characters you've typed. If something exists, the shell fills out the partially typed name with the proper characters. You can then press Enter to execute the command or continue typing other options and arguments. This feature, called either filename or command completion, makes the shell much easier to use. In addition to keystrokes for editing the command line, the shell interprets several keystrokes that control the operation of the currently executing program. Table 7-2 summarizes these keystrokes. For example, typing Ctrl-C generally cancels execution of a program. This keystroke command is handy, for example, when a program is taking too long to execute and you'd prefer to try something else.
Several other special characters control the operation of the shell, as shown in Table 7-3. The # and ; characters are most often used in shell scripts, which you'll learn about in more detail later in this chapter. The & character causes the shell prompt to return immediately instead of waiting for a command to finish; the command runs in the background and you can continue to enter more commands. |
[ Team LiB ] |