Best practices for editing configuration files
From openSUSE
GNU/Linux is an operation system that historically relies on plain text files for configuration of programs or daemons. This is partly due to graphical configuration tools, such as YaST, not being available in the past. But mostly users like the simple handling and editing of files and programs can easily read them.
This article outlines the best practices I collected so far and is suited for beginning users and up.
Contents |
Using the Shell
As an advanced user, you are going to use the shell anyway, so I will just teach it. Believe me, once you get the hang of it you will be faster. Once you have opened up your terminal like konsole, you can become root by using su -. Let's assume that you opened a konsole window under KDE from the menu or via ALT-F2, konsole.
user@linux:~$ su - Password: linux:~#
You can now edit configuration files as root. Don't forget to use the exit command when you are done.
sam:~# whoami root sam:~# exit logout user@linux:~$
Finally, for more comfort, the KDE Konsole program let's you create a root shell from the Session menu with a click.
Make a Backup
When you make a change to a known working configuration, make a backup copy. This simple step allows you to go back to where you were in case you mess it up.
$ cp -iv fooconf fooconf-back
Or if you plan on having several backups, use this command to create a backup file containing the date and time:
$ cp fooconf fooconf-`date +%y%m%d-%H%M%S`
Use a Good Editor
You can use the editor of you choice. If you are editing in a shell, I recommend the nano editor. Some configuration files, such as /etc/fstab, have long lines. Use the -w switch to set nano not to wrap them.
$ nano -w /etc/fstab
The nano editor displays the main functions on the screen, CTRL-K cuts a line, CTRL-U uncuts (pastes) it, CTRL-O saves the file, CTRL-X exits.
Backup Lines
Most configurations files have comments. Those are lines that are ignored because they start with a certain character, such as #. You can use that to remind yourself of what you edited by keeping the old line just above it and turning it into a comment by placing a # at the beginning of the line. You can do that very easily in nano. Cut the line and uncut it twice (CTRL-K CTRL-U CTRL-U), and add a #. Here is an example:
Before:
# foo configuration file EnableFeatureBar = 0
After:
# foo configuration file # EnableFeatureBar = 0 EnableFeatureBar = 1
RTFM, Read The Fine Manual
If want to edit configuration files, you should read first. The author uses GNU/Linux for 8 years now but still has the documentation open if anything is unclear. Most configuration files come with inline explanation as comments, a fully documented example file or a manual page. Places to look in are:
- the file itself
- <programname>
- man <filename>
- /usr/share/doc/packages/<packagename>/
- the program's project homepage and other help sources
Below is the beginning of /etc/samba/smb.conf as an example.
# smb.conf is the main Samba configuration file. You find a full commented
# version at /usr/share/doc/packages/samba/examples/smb.conf.SUSE if the
# samba-doc package is installed.
# Date: 2007-12-04
[global]
workgroup = WORKGROUP
printing = cups
Updating Programs
When you install new versions of a program, you may have edited its configuration file. The package manager backend, rpm, will notice that. It won't overwrite your files so your changes will not be lost. Depending on the package, your files will either
- stay in place and the new files will be put into the same directory with the suffix .rpmnew or
- be renamed to have the suffix .rpmsave or .rpmorig, and the packages' new file will be put in place.
Editing the Right Thing
You will have noticed that there are many GNU/Linux distribution out there. Other distributions may have different versions of packages or different programs for the same functionality altogether. This means that not everything you find on the internet can be copied into your configuration. It may range from as simple as a differently named file to mayor loss of functionality.
One example for that is the apache's httpd.conf file, which is not supposed to be edited in openSUSE altogether. Instead, it is created new everytime the webserver is started, from settings in other files inside the /etc/sysconfig/ directory.
If on the first lines of the configuration file it sais not to edit it, just don't do it. It might say where the appropriate place is. In either case, refer to the documentation as mentioned above.
See Also
- Concepts -- An introduction to many openSUSE/Linux concepts
- Documentation -- other openSUSE documentation

