[ Team LiB ] Previous Section Next Section

7.3 Useful Linux Programs

This section presents several programs you may find helpful in working with your Linux system. You'll learn several commands that report system status and you'll learn how to use pico, a simple text editor.

7.3.1 Viewing System Information

Linux provides a number of commands that report system status. The most commonly used commands are shown in Table 7-8. These commands can help you troubleshoot system problems and identify resource bottlenecks. Although each command can be used without options or arguments, each supports options and arguments that let you customize operation and output; consult the appropriate manpage for details.

Table 7-8. Useful system commands

Command

Function

df

Shows the amount of free disk space (in 1 KB blocks) on each mounted filesystem.

du

Shows the amount of disk space (in 1 KB blocks) used by the working directory and its subdirectories. With the -s option, displays just a summary without listing all the subdirectories and files.

free

Shows memory usage statistics, including total free memory, memory used, physical memory, swap memory, shared memory, and buffers used by the kernel.

ps

Shows the active processes (instances of running programs) associated with this login session. Use the -a option to list all processes.

top

Shows a continually updated display of active processes, and the resources they are using. Type the q key to exit.

uptime

Shows the current time, the amount of time logged in, the number of users logged in, and system loadaverages.

users

Shows each login session.

w

Shows a summary of system usage, currently logged-in users, and active processes.

who

Shows the names of users currently logged in, the terminal each is using, the time each has been logged in, and the name of the host from which each logged in (if any).

7.3.2 Using the pico Editor

If you're working under X, you have access to a variety of GUI text editors. However, GUI text editors cannot be used from a virtual console. The pico editor is a simple text editor that you can think of as the Linux equivalent of the Windows program named Edit, because it can be used in graphical or text mode.

Unfortunately, the pico text editor is not a part of the standard Red Hat Linux installation. The standard Red Hat Linux installation does include the text editor vi; however, vi is more difficult to learn than pico. To install the pico editor, install the pine package that contains the editor and the pine email client. To do so, mount installation CD 3, open a terminal window, and issue the command:

$ redhat-install-packages /mnt/cdrom/RedHat/RPMS/pine-*.rpm

If X is not running, this command to install the pine package will fail. Instead, issue the following commands to mount the CD and install the package:

$ mount -t iso9660 /dev/cdrom /mnt/cdrom -o ro
$ rpm -Uvh /mnt/cdrom/RedHat/RPMS/pine-*.rpm

To start pico, simply type pico at the shell prompt, or if you want to edit a particular file, type pico followed by the name of the file (or the file's path, if the file is not in the working directory). For example, to edit the file mydata, type:

 [bill@home bill]$ pico mydata

Figure 7-5 shows pico's standard display. At the top of the display is a status line, which shows the version of the program and the name of the file being edited (or New Buffer, if the file is new). If the file has been modified, the upper-right corner of the display contains the word Modified. The bottom two lines of the display list the available editing commands. Most of the commands require you to type a control character, so that commands can be distinguished from characters you want to add to the buffer, as pico's work area is termed. Typing an ordinary character inserts it at the current cursor position. You can use the cursor keys to move around the display; you can use the Delete or Backspace key to erase unwanted characters. Some commands use the third line from the bottom to report status and obtain additional input.

Figure 7-5. The pico editor
figs/rh3_0705.gif

Table 7-9 summarizes pico's commands. Notice that the command Ctrl-G accesses pico's help system. You can access several of the commands by using function keys; for example, pressing F1 has the same result as typing Ctrl-G.

Table 7-9. Summary of pico commands

Command

Description

Ctrl-^

Mark the cursor position as beginning of selected text.

Ctrl-A

Move to the beginning of the current line.

Ctrl-B

Move backward one character.

Ctrl-C (F11)

Report the current cursor position.

Ctrl-D

Delete the character at the cursor position.

Ctrl-E

Move to the end of the current line.

Ctrl-F

Move forward one character.

Ctrl-G (F1)

Display help.

Ctrl-I

Insert a tab at the current cursor position.

Ctrl-J (F4)

Format the current paragraph.

Ctrl-K (F9)

Cut selected text.

Ctrl-L

Refresh the display.

Ctrl-N

Move to the next line.

Ctrl-O (F3)

Save the current buffer to a file.

Ctrl-P

Move to the previous line.

Ctrl-R (F5)

Insert an external file at the current cursor position.

Ctrl-T (F12)

Invoke the spelling checker.

Ctrl-U (F10)

Paste text at the current cursor position.

Ctrl-V (F8)

Move forward one page of text.

Ctrl-W (F6)

Search for text, neglecting case.

Ctrl-X (F2)

Exit pico, saving the edit buffer.

Ctrl-Y (F7)

Move backward one page of text.

Here's a simple exercise that will give you a quick tour of pico. Start pico by issuing the command:

pico

Then type the following short paragraph of text, including the typographical errors:

Pico is is a greet editor. I use it for my light-duty tasks editing. However, when I 
need to really get down to business, I prefer vi.

Notice that three errors appear:

  • The word is appears twice

  • Great is misspelled as greet

  • The words editing and tasks appear in the wrong order.

To correct the first error, use the up and left arrow keys to position the cursor on the letter i of the first instance of the word is. Then, press Del three times to erase the word and the following space.

Next, use the right arrow key to place the cursor on the second (incorrect) letter e in the misspelled word greet. Type an a and press Del to correct the error by replacing the e with an a.

Now, let's revise the phrase "for my" to read "for all my." Simply use the right arrow keys to move to the letter m in the word my. Type all and a space.

Finally, let's cut and paste to move the words tasks and editing into their proper sequence. Use the arrow keys to position the cursor on the letter t in the word tasks. Type Ctrl-^ to mark the beginning of a selection. Use the right arrow key to select the remainder of the word and the following text, positioning the cursor on the letter e in the word editing. Cut the selected word by typing Ctrl-K. Now, use the right arrow key to move the cursor past the word editing and type Ctrl-U to paste the text that was cut. The paragraph is now error-free.

Save the paragraph to a file by typing Ctrl-X, responding y to the question "Save modified buffer?", typing the desired filename, and pressing Enter. Use the less command to verify that the file was created and has the proper contents.

    [ Team LiB ] Previous Section Next Section