Certification Objective 1.02-Basic Linux Knowledge

Linux and Unix are managed through a series of text files. Linux administrators do not normally use graphical editors to manage these configuration files. Editors such as WordPerfect, OpenOffice.org Writer, and yes, even Microsoft Word normally save files in a binary format that Linux can't read.

Popular text editors for Linux configuration files include nano, pico, joe, and vi. If you already know one of these editors, feel free to skip this section. If you have to rescue an RHEL 5 system (as may be required during the exam), you'll have access to these editors when booting your system from RHEL 5 rescue media.

The VIsual Editor

While emacs may be the most popular and flexible text editor in the world of Linux, I believe every administrator needs at least a basic knowledge of vi, which may help you save a broken system. If you ever have to restore a critical configuration file using an emergency boot floppy, vi is probably the only editor that you'll have available.

In reality, RHEL 5 uses an enhanced version of the vi editor, known as vim. And as RHEL emergency boot media access installation packages, it supports more console-based editors. I describe vi here simply because it's the editor I know best.

On the Job 

If you boot in rescue mode and try to start emacs or pico, that starts the joe editor instead.

You should know how to use the two basic modes of vi: command and insert. When you use vi to open a file, it opens in command mode. Some of the commands start insert mode. Opening a file is easy: just use the vi filename command. By default, this starts vi in command mode. An example of vi with the /etc/inittab file is shown in Figure 1-1.

image from book
Figure 1-1: The vi editor with/etc/inittab

The following is only the briefest of introductions to the vi editor. For more information, there are a number of books available, as well as an extensive manual formatted as a HOWTO available from the Linux Documentation Project at www.tldp.org. Alternatively, a tutorial is available through the vimtutor command.

vi Command Mode

In command mode, you can do everything you need to a text file except edit it. The options in command mode are broad and varied, and they are the subject of a number of book-length texts. In summary, vi requires seven critical command skills:

  • Open To open a file in the vi editor from the command line interface, run the vi filename command.

  • Search Start with a backslash, followed by the search term. Remember, Linux is case-sensitive, so if you're searching for "Michael" in /etc/passwd, use the /Michael (not /michael) command.

  • Write To save your changes, use the w command. You can combine commands: for example, :wq writes the file and exits vi.

  • Close To leave vi, use the :q command.

  • Abandon If you want to abandon any changes that you've made, use the :q! command.

  • Edit You can use a number of commands to edit files through vi, such as x, which deletes the currently highlighted character; dw, which deletes the currently highlighted word; and dd, which deletes the current line. Remember, p places text from a buffer, and U restores text from a previous change.

  • Insert A number of commands allow you to start insert mode, including i to start inserting text at the current position of the editor, and o to open up a new line immediately below the current position of the cursor.

Basic Text Editing

In modern Linux systems, editing files with vi is easy. Just use the normal navigation keys (arrow keys, PAGE UP, and PAGE DOWN), and then one of the basic commands such as i or o to start vi's insert mode, and type your changes directly into the file.

When you're finished with insert mode, press the ESC key to return to command mode. You can then save your changes or abandon them and exit vi.

On the Job 

There are several specialized variations on the vi command. Three are vipw, vigw, and visudo, which edit /etc/passwd, /etc/group, and /etc/sudoers, respectively.

Exercise 1-1: Using vi to Create a New User

image from book

In this exercise, you'll create a new user by editing the /etc/passwd file with the vi text editor. While you could create new Linux users in other ways, this exercise helps you verify your skills with vi and at the command line interface.

  1. Open a Linux command line interface. Log in as the root user, and type the vipw command. This command uses the vi editor to open /etc/passwd.

  2. Navigate to the last line in the file. As you should already know, there are several ways to navigate in command mode, including the DOWN ARROW key, the PAGE DOWN key, the G command, or even the K key.

  3. Make one copy of this line. If you're already comfortable with vi, you should know that you can copy an entire line to the buffer with the yy command. This "yanks" the line into buffer. You can then restore or "put" that line as many times as desired with the p command.

  4. Change the username, user ID, group ID, user comment, and home directory for the new user. If you understand the basics of Linux or Unix, you'll understand their locations on each line in the /etc/passwd file. For example, in Figure 1-2, this corresponds to gb, 501, 501, Gordon Brown, and /home/gb. Make sure the username also corresponds to the home directory.

  5. Return to command mode by pressing the ESC key. Save the file with the :w command, and then exit with the :q command. (You can combine the two commands in vi; the next time you make a change and want to save and exit, run the :wq command.)

  6. As the root user, run the passwd newuser command. Assign the password of your choice to the new user.

image from book
Figure 1-2: Adding a new user in /etc/passwd

image from book

Other Text Editors

You can use any available text editor during the Red Hat exams. But do not count on any GUI text editors, as the GUI may not be available for troubleshooting during the exam, or in real life.

RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302)
Linux Patch Management: Keeping Linux Systems Up To Date
ISBN: 0132366754
EAN: 2147483647
Year: 2004
Pages: 227
Authors: Michael Jang

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