this:
$ /sbin/ifconfig
As you can see in this example, the ifconfig
command is indeed installed. What happened is that by default, the /sbin
directory is not in your $PATH
. One of the reasons for this is that commands under the /sbin
directory are normally intended to be run only by root. You can add /sbin
to your $PATH
by editing the file .bash_profile
in your home directory (if you use the bash
shell by default, like most Linux users). Look for the following line:
PATH=$PATH:$HOME/bin
You can then edit this file, perhaps using the vi
editor (discussed in this chapter), to add the /sbin
directory like so:
PATH=$PATH:/sbin:$HOME/bin
Save the file. The next time you log in, the /sbin
directory is in your $PATH
. One way to use this change right away is to read in the new settings in .bash_profile
by using the bash
shell's source command as follows:
$ source .bash_profile
You can now run ifconfig
without the need to explicitly type its full pathname.
Some Linux commands also use environment variables — for example, to acquire configuration information (such as a communications program looking for a variable such as BAUD_RATE
, which might denote a default modem speed).
To experiment with the environment variables, you can modify the PS1
variable to manipulate the appearance of your shell prompt. If you are working with bash,
you can use its built-in export
command to change the shell prompt. For example, if your default shell prompt looks like
[andrew@teletran ~]$
you can change its appearance by using the PS1 variable like this:
$ PS1='$OSTYPE r001z ->'
After you press Enter, you see the following:
linux-gnu r001z ->
See the bash
man page for other variables you can use for prompt settings.
Using the Text Editors
Linux distributions include a number of applications known as
Some of the console-based text editors are as follows:
> emacs
— The comprehensive GNU emacs
editing environment, which is much more than an editor; see the section 'Working with emacs'
later in this chapter
> joe
— Joe's Own Editor, a text editor, which can be used to emulate other editors
> nano
— A simple text editor similar to the pico
text editor included with the pine
email program
> vim
—An improved, compatible version of the vi
text editor (which we call vi
in the rest of this chapter because it has a symbolic link named vi
and a symbolically linked manual page)
Note that not all text editors described here are screen oriented. Some of the text editors for the X Window System, which provide a graphical interface, such as menu bars, buttons, scrollbars and so on, are the following:
> gedit
— A GUI text editor for GNOME
> kate
— A simple KDE text editor
> kedit
— Another simple KDE text editor
A good reason to learn how to use a text-based editor, such as vi,
is that system maintenance and recovery operations generally never take place during X Window sessions (negating the use of a GUI editor). Many larger, more complex and capable editors do not work when Linux is booted to its single-user or maintenance mode. See Chapter 11 for more information about how Fedora boots. If anything does go wrong with your system, you probably won't be able to get into the X Window System, making knowledge and experience of using both the command line and text editors such as vi important. Make a point of opening some of the editors and playing around with them; you never know — you might just thank me someday!
Another reason to learn how to use a text-based editor under the Linux console mode is so that you can edit text files through dialup or network shell sessions because many servers do not host graphical desktops.
Working with vi
The editor found on nearly every UNIX and Linux system is, without a doubt, the vi
editor, originally written by Bill Joy. This simple-to-use but incredibly capable editor features a somewhat cryptic command set, but you can put it to use with only a few commands. Although more experienced UNIX and Linux users continue to use vi
extensively during computing sessions, many newer users might prefer learning an easier-to-use text editor such as pico
or GNU nano.
Diehard GNU fans and programmers definitely use emacs.
That said, learning how to use vi
is a good idea. You might need to edit files on a Linux system with a minimal install, or a remote server without a more extensive offering of installed text editors. Chances are better than good that vi
will be available.
You can start an editing session by using the vi
command like this:
$ vi file.txt
The vi
command works by using an insert (or editing) mode, and a viewing (or command) mode.
When you first start editing, you are in the viewing mode. You can use your cursor or other navigation keys (as shown later) to scroll through the text. To start editing, press the i
key to insert text or the a
key to append text. When finished, use the Esc key to toggle out of the insert or append modes and into the viewing (or command) mode. To enter a command, type a colon (:
), followed by the command, such as w
to write the file, and press Enter.
Although vi
supports many complex editing operations and numerous commands, you can accomplish work by using a few basic commands. These basic vi
commands are the following: