Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

What Are Config Files, and How Can You Edit Them?

$
0
0

What Are Config Files, and How Can You Edit Them?

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 usedSQLite 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.

Some config files are structured in a format of the developer’s own design. Others use widely-known standards used to structure data, like JSON (javascript Object Notation), YAML (YAML Ain’t Markup Language) or XML (eXtensible Markup Language) format. Some programs load the information stored in their config files when they start, while others periodically check to see if it has been changed.


What Are Config Files, and How Can You Edit Them?

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 , orset 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.


What Are Config Files, and How Can You Edit Them?

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, whichall begin with a hash symbol.


What Are Config Files, and How Can You Edit Them?

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”.

One program which follows this particular convention is the Vim text editor . In the past, we’ve talked about how to customize VIM by editing its config file .

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 .


What Are Config Files, and How Can You Edit Them?

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.


What Are Config Files, and How Can You Edit Them?

On Linux, the closest analog to Notepadis 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.

Thefirstis 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 .


What Are Config Files, and How Can You Edit Them?

The second common problemis 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 re

Viewing all articles
Browse latest Browse all 11063

Trending Articles