The vast majority of the computer programs we use — be they office suites, web browsers, or even video games — are configured through a system of menu interfaces. It has almost become the default way we use our machines. But some programs require you to take a step beyond that, and you actually have to edit a text file in order to get them to run as you wish.
These text files are — unsurprisingly enough — called “config files”. If you want to take the leap from “user” to “power user”, you’re going to need to know how to tweak them.
What Are Config Files?
Before we get into the technical nitty-gritty, let’s first concretely define what a configuration file is.
Config files are essentially files that contain information required for the successful operation of a program, which are structured in a particular way. Rather than being hard-coded in the program, they are user-configurable, and are typically stored in a plaintext file (although I have previously seen programs that have used SQLite databases as their config files).
Surprisingly, there’s no defined standard on how config files should work, or what they should look like. It’s entirely up to the whim of the developer of the program.
If you’re a Linux user, you’re probably going to be familiar with these, as many basic maintenance tasks require you to edit config files. If you want to tweak GRUB to dual-boot your system , or set up a web server , you’re going to have to deal with them.
Although it’s not an exclusively Linux thing. Depending on what you’re doing, you might have to edit them in Windows or Mac OS X.
What Do Config Files Look Like?
Now, let’s take a look at some real-world config files. As we mentioned earlier, they come in all different shapes and sizes. One config file you’re almost certainly familiar with is the hosts file, which is used on Windows, Mac, and Linux to manually map IP addresses to hostnames.
On Windows, you can find it under c:\windows\system32\drivers\etc\hosts. On Mac and Linux, it’ll be in /etc/hosts.
As you’ll notice, the hosts file uses whitespace to separate elements, with each hostname having its own line. Furthermore, the hosts file allows the user to add annotations and comments, which all begin with a hash symbol.
On Linux and Mac OS X, some programs require the user to store the config file in the home directory, with a period at the beginning of the filename. These config files sometimes have the file extension .rc, and are colloquially called “dotfiles”.
Config files are even used by video games to define and control some of the behavior, such as keymappings. The config file below is taken from Black Mesa — a fan-made remake of the original Half Life.
In the original Deus Ex, which was released in 2000, the user actually had to edit the config file to enable cheats!
How to Edit Config Files
So, now we know what config files are used for, let’s talk about how we can edit them.
To do this, you’re going to need a text editor. Don’t use a word processor, as these can add formatting to the file which would prevent them from being read by the program.
Windows users already have a text editor pre-installed. I’m talking about Notepad. Although it’s worth stressing that there are a number of great third-party text editors available for Windows, including Notepad++, Atom, and Sublime Text Editor.
On Linux, the closest analog to Notepad is Gedit . You also might want to consider using a command-line text editor, like Nano or Vim . For the sake of sheer efficiency, I heavily lean towards the Vim text editor. This makes it easy for me to precisely jump to different positions within the config file, simply by using just a handful of keystrokes.
On Mac OS X (or MacOS Sierra, is it will soon be known ), there are a number of text editors that come pre-installed. You’re probably familiar with TextMate. It also includes a number of command-line text editors, like Vim and Nano.
When you edit the file, it’s important to ensure you follow the conventions of it. This can be worked out just by looking at it. Some config files, like the hosts file, will explain these conventions to you. Others will force you to read some documentation, or a couple of blog posts.
Finally, if the config file being edited is structured in a JSON or XML format, you might want to use a more powerful text editor with syntax highlighting. I recommend Atom. This will improve your accuracy by showing you when you’ve made a mistake.
What If It Isn’t Working?
Finally, let’s touch on what happens when things go wrong. In my own experience, the problems associated with editing config files tend to fall into two camps.
The first is permissions. If you’re unable to save your changes, it could be because you’re trying to do it as an ordinary user. In order to prevent accidental damage, many config files are only editable by those with administrator-level privileges.
Fixing this is easy. On Mac and Linux, try escalating your privileges with the sudo command. So, if you were editing your hosts file, you’d run:
sudo nano /etc/hosts
On Windows, right-click Notepad (or whatever text editor you’re using) and select Run as administrator.
The second common problem is user error. If things aren’t working, it might be your fault. Check that you haven’t made any typos, and that you’ve followed the conventions of the config file. It does sound obvious, I know, but a simple spelling mistake, or forgetting to close a pair of speech marks can render your entire file useless.
A good way to avoid problems is to make a copy of the config file before you make any changes. This way, if something goes wrong, you can restore the copy and start again!
Config Files Are Important
More than important, they’re an essential part of using Linux. Knowing how to properly edit them can help you endlessly.
Are there any other essential skills you feel that beginner-to-intermediate Linux users need to know? Let me know in the comments below.