Doug's Linux Notebook

Text Editors &
Editing Config Files

At some point during your setting up of your Linux system you will likely need to edit a text configuration file. It may be to add an entry to /etc/fstab, or make changes to XF86Config or some other file, but I can almost guarantee you will spend some time with a text editor, but which one? As with most things in Linux there are several choices, Vi, Emacs, Pico, Joe, just to name a few.

VI is a powerful editing tool and is very popular but it is also very different from anything else and requires some time spent to learn to use it. I cringe whenever I see someone on a help forum tell a newbie to use Vi to edit some file to fix there problem, I just know that they won't know how to use Vi and will only add to there frustration. The first time I tried to use Vi I couldn't do anything with it, so I gave up then couldn't even figure out how to exit.

Don't get me wrong, I'm not saying Vi is bad, I think it is a great tool and everyone should learn to use it as it comes standard on all Linux distributions and even other UNIX systems such as BSD and Solaris.

To learn Vi type "vimtutor" in a terminal, if that doesn't work try an internet search. The tutor is simply a text file that you open with Vi , follow the instructions and do the examples.

I usually suggest to use Pico, it is installed on most systems and is very easy to use. Pico is part of the Pine command line email program so if Pico is not on your system install Pine. Or you could download and install Nano, Nano is very similar to Pico with a few enhancements. I use Nano alot.

Pico (or Nano)is very straight forward, simply place the cursor where you want and start typing, backspace to delete and there is a list of keyboard commands such as "ctrl+o" to save and "ctrl+x" to exit displayed at the bottom of the screen.

Editing config files

To edit most configuration files you will need root access, unless it is a file in your home directory. You should always make a backup copy of the file you are working on, this can really help keep you out of trouble.

Most Linux config files contain a lot of comments, these can be very helpful for figuring out what different sections are for and finding the part of the file you need to edit. Lines that begin with # are comments and are ignored by the program using the file. I use comments when I add a line to a config file to note when and why it was added Often when I change a line I comment out the original and add my modified line below it, this way my changes can easily be undone later if necessary by simply commenting or deleting the modified line and uncomment the original.

To uncomment a line in a configuration file means to delete the # at the start of the line. Some configuration files contain many commented lines for setup of different hardware, software, or options and you simply uncomment the lines needed for your setup .

Let's look at an example of editing a config file. We will add a line to /etc/fstab to mount the Windows C: drive on startup.

Open the fstab file with your favorite editor.

[doug@linux]$ su
password root password
[root@linux]$ nano /etc/fstab

Then place the cursor where you want to add the line. What I added is the bold type below, notice the comment lines.

# This is the root Linux system.

/dev/hda6

/

ext3

defaults

0 1

# for access to win drives

/dev/hda1

/mnt/vfat/C

vfat

defaults,ro

0 0

/dev/hda2

/mnt/vfat/D

vfat

defaults,ro

0 0

# 0ther devices.

/dev/cdrom

/media/cdrom

auto

defaults,user

0 0

/dev/fdoppy

/media/floppy

auto

defaults,user

0 0

proc

/proc

proc

defaults

0 0

none

/dev/pts

devpts

gid=5,mode=666

0 0

/dev/hda5

none

swap

sw

0 0

This is meant as an example of editing config files not instructions for accessing Windows drives, There is a little more to accessing your Windows drives than is covered here, For more information on that subject see Accessing Windows Drives.

Back to the Main Page