Basic Utilities


One of the important advantages of Linux is that it comes with thousands of utilities that perform myriad functions. You will use utilities whenever you work with Linux, whether you use them directly by name from the command line or indirectly from a menu or icon. The following sections discuss some of the most basic and important utilities; these utilities are available from a character-based interface. Some of the more important utilities are also available from a GUI; others are available only from a GUI.

Folder


The term directory is used extensively in the next sections. A directory is a resource that can hold files. On other operating systems, including Windows and Macintosh, and frequently when speaking about a Linux GUI, a directory is referred to as a folder. That is a good analogy: A traditional manila folder holds files just as a directory does.

Tip: In this chapter you work in your home directory

When you log in on the system, you are working in your home directory. In this chapter that is the only directory you use: All the files you create in this chapter are in your home directory. Chapter 6 goes into more detail about directories.


ls: Lists the Names of Files

Using the editor of your choice, create a small file named practice. (A tutorial on the vim editor appears on page 152.) After exiting from the editor, you can use the ls (list) utility to display a list of the names of the files in your home directory. In the first command in Figure 5-1 (next page), ls lists the name of the practice file. (You may also see files the system or a program created automatically.) Subsequent commands in Figure 5-1 display the contents of the file and remove the file. These commands are described next.

Figure 5-1. Using ls, cat, and rm on the file named practice

$ ls practice $ cat practice This is a small file that I created with a text editor. $ rm practice $ ls $ cat practice cat: practice: No such file or directory $

cat: Displays a Text File

The cat utility displays the contents of a text file. The name of the command is derived from catenate, which means to join together, one after the other. (Figure 7-8 on page 212 shows how to use cat to string together the contents of three files.)

A convenient way to display the contents of a file to the screen is by giving the command cat, followed by a SPACE and the filename. Figure 5-1 shows cat displaying the contents of practice. This figure shows the difference between the ls and cat utilities: The ls utility displays the name of a file, whereas cat displays the contents of a file.

rm: Deletes a File

The rm (remove) utility deletes a file. Figure 5-1 shows rm deleting the file named practice. After rm deletes the file, ls and cat show that practice is no longer in the directory. The ls utility does not list its filename, and cat says that no such file exists. Use rm carefully.

Tip: A safer way of removing files

You can use the interactive form of rm to make sure that you delete only the file(s) you intend to delete. When you follow rm with the i option (see page 105 for a tip on options) and the name of the file you want to delete, rm displays the name of the file and then waits for you to respond with y (yes) before it deletes the file. It does not delete the file if you respond with a string that does not begin with y. The i option is set up by default for the root user under Red Hat Linux:

$ rm -i toollist rm: remove regular file 'toollist'? y


Optional: You can create an alias (page 318) for rmi and put it in your startup file (page 170) so that rm always runs in interactive mode.


less Is more: Display a Text File One Screen at a Time

Pagers


When you want to view a file that is longer than one screen, you can use either the less utility or the more utility. Each of these utilities pauses after displaying a screen of text. Because these utilities show one page at a time, they are called pagers. Although less and more are very similar, they have subtle differences. At the end of the file, for example, less displays an EOF (end of file) message and waits for you to press q before returning you to the shell. In contrast, more returns you directly to the shell. In both utilities you can press h to display a Help screen that lists commands you can use while paging through a file. Give the commands less practice and more practice in place of the cat command in Figure 5-1 to see how these commands work. Use the command less /etc/termcap instead if you want to experiment with a longer file. Refer to the less man page for more information.

hostname: Displays the System Name

The hostname utility displays the name of the system you are working on. Use this utility if you are not sure that you are logged in on the right machine.

$ hostname bravo.example.com





A Practical Guide to Red Hat Linux
A Practical Guide to Red HatВ® LinuxВ®: Fedoraв„ў Core and Red Hat Enterprise Linux (3rd Edition)
ISBN: 0132280272
EAN: 2147483647
Year: 2006
Pages: 383

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net