Certification Objective 1.01: Basic Linux Knowledge

 < Day Day Up > 



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, StarOffice, 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 emacs, pico, joe, and vi.

The Visual Editor

While emacs may be the most popular text editor in the world of Linux, every administrator needs at least a basic knowledge of vi. While emacs may be more popular and flexible, vi 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 3 uses an enhanced version of the vi editor, known as vim. It adds color to different types of variables in key configuration files such as /etc/fstab. All regular vi commands work in the vim editor. While you can remove the coloring in the vim editor with the :nohl command, this detail does not affect your ability to manage your Linux system.

You need to know how to restore your system from a rescue floppy, which does not have enough room to carry any editor other than vi. However, the Red Hat Exam Prep guide suggests that you need to be able to 'use the rescue environment provided by the first installation CD,' which does include other console editors. If you use the joe text editor, it's available when you boot from the rescue floppy.

On The Job 

This section provides only the briefest of introductions to the vi editor.

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/passwd file is shown in Figure 1-1.

click to expand
Figure 1-1: The vi editor

The following is only a brief introduction 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.

vi Command Mode

In command mode, you can do everything you need to do 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. Using 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.

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

start example

In this exercise, you'll create a new user by editing the /etc/passwd file with the vi text editor. While there are other ways to create new Linux users, 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 vi /etc/passwd command.

  2. Navigate to the last line in the file. As you should already know, there are several ways to do this 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 tb, 501, 501, Tony Blair, and /home/tb. Make sure the username also corresponds to the home directory.

    click to expand
    Figure 1-2: Adding a new user in /etc/passwd

  5. Return to command mode by pressing the ESC key. Save the file with the wq command.

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

end example



 < Day Day Up > 



RCHE Red Hat Certified Engineer Linux Study Guide[c] Exam (Rh302)
RCHE Red Hat Certified Engineer Linux Study Guide[c] Exam (Rh302)
ISBN: 71765654
EAN: N/A
Year: 2003
Pages: 194

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