Editing Linux program files with simple text editors

345

Author: JT Smith

– by Robin “Roblimo” Miller
Most tutorials about editing Linux system or program files assume you are going to
use either the vi or emacs editors preferred by a majority of skilled programmers. These are great editors for programmers, but those of us who only edit a program file once in a while may be better off using simpler text editors like Pico, Gedit, Kedit or my personal favorite, Nedit.
The secret of using your text editor as root
No matter what text editor you use, to edit program files you must first log in as root. The easiest way to do this from KDE or Gnome or any other Gnu/Linux graphical desktop is through a terminal window. Call one up, type “su” and you’ll see “Password:” right below it. Type your root password, and anything you do in that terminal window from then on will be done as root. You will be able to edit any file on your computer as long as you open your chosen text editor in that terminal window.

Pico
Pico is probably the simplest and easiest-to-learn “command line” text editor there is. It is included with almost every packaged Linux distribution but may not be installed by default. If it’s not installed on your Linux computer, install the Pine email package and you will automatically have Pico even if you don’t use Pine. To start Pico in your “root” terminal window, type “Pico” and there it is, ready to use, with the most important commands lined up at the bottom of the terminal window in case you are one of the people who (like me) has trouble remembering which keystrokes do what in which programs. To save time, you can type the name of the program file you need to edit right after the word “pine” like this — pico /usr/lib/office52_en/program/soffice -- with a space between the word “pico” and the program file’s full name.

Because Pico is a command line editor, your mouse won’t work. You need to move around the text by scrolling up and down and side to side with the “arrow” keys or up and down with pageup/pagedown keys. But if you are pasting in text from a tutorial or Web page you can do the usual Linux “middle mouse button” (or “both buttons at once”) one-click paste wherever you have put your cursor in that Pico screen. You may want to practice this and other Pico commands for a few minutes on a text file you don’t care about before using it to actually edit an important program file.

Using GUI text editors on program files
I am going to use Nedit in this example because it’s the editor I prefer, but the same instructions work in Gedit, Kedit or almost any other simple “point and click” GNU/Linux text editor.

Whichever editor you choose — and at least one of these comes with almost every packaged Linux distribution — you must open it in your “root” terminal window to use it to edit anything outside of your home/yourname directory. Once you’ve opened a terminal window and done the “su password” routine, all you need to do is type your chosen editor’s name, and up it comes. Now you need to find the file you want to edit. This can be slightly more tedious in a point/click editor than in a command line editor, but not enough to worry about. If we’re looking for /usr/lib/office52_en/program/soffice for instance, we click on the “file” button at the left side of the toolbar on top of our text editor’s screen and select “open” from the drop-down menu. This brings up a “select file” window. Their appearance varies from editor to editor — I’ve used Nedit’s version here — but they all work pretty much the same way.

Note that we’ve typed the directory we want in the top “filter” line and are looking at a list of files within that directory in a box at the right side of this little box on our screen. We can get to that directory in a number of ways, including typing its name into the “filter” space directly or by starting with “/” and from the “Directories” selections that would give us, choosing “/usr” and getting another “Directories” list, then selecting “/lib” and doing this again to get “/usr/lib/office52_en/” and once again to get to the “/usr/lib/office52_en/program/” directory. This is a lot faster to do than to describe. Which way you chose depends on whether you prefer to type or click. You end up in the same place either way. Now click “OK” and the file opens up in Nedit (or whatever editor you choose) and you are ready to edit it any way you want.

Now you are on familiar ground if you have ever done any text editing at all in any “point and click” text editor — in any operating system. You have all your usual text editing features available, including “undo” if you make a mistake.

(Since you are editing files that control your computer, you want to be extra-careful to get everything right before you hit that all-important “Save” button and consider your work finished, so that one-click “undo” command is a great one to have handy here.)

Hopefully, you are editing files in accordance with instructions from someone who knows more than you (or I) do or are working from a “How To” or “Read me” file or getting your editing instructions from a trusted Web site. In this example, we are curing a problem StarOffice has when it is run on a system with a Savage S-3 video driver: start StarOffice and the system locks up and won’t work. The “Read me” file included with StarOffice says that if we insert the one-line command export SAL_DO_NOT_USE_INVERT50=true this problem will go away.

(StarOffice documentation did not say in which file this line should be inserted, but that’s another issue. I found out from a “Linux guru” buddy — and saved his exact instructions on a floppy disk in case I needed them again after a reinstall, which I eventually did.)

How often do you edit programs or system files?
This is the key question. If your work will benefit from using a programmer-oriented editor or you are using Linux as a training tool because you hope to become a programmer or network administrator in the future, you probably should learn to use vi or emacs — or both. But if you use Linux for nothing but user-level Web surfing or office work and only dabble with your system once in a while, you don’t need a complex editing program. Performing a simple, user-level system maintenance or modification task only requires a simple tool — like one of the many “point and click” text editors for Linux that almost anyone can learn to use in a minute or two.

Note: No matter what text editor you prefer, an excellent reference for Linux users trying to figure out “what’s going on in there” is The Linux Cookbook by Michael Stutz. It is a great introduction to Linux at the “command line” level.

Category:

  • Linux