Sunday, January 17, 2016

How to Find Configuration Files in Linux (GNOME example)

When you change the computer's setting or configuration, the change must be saved as a file somewhere. This means that if you search through your files system for files that have been created or modified after you have applied the change, you will be able to locate exactly where your setting or configuration is stored on the system.

For example, assume you want to change the font size of the default terminal profile. Well, when you apply the change, this must have changed some file on the system that saves this setting, but what is this file and where is this file even located?

In this post, we will look into ways to locate exactly which files have been modified and how using find command in terminal. The basic idea is pretty simple: you simply look for all files on the system that have been modified since you have applied the change. Here is step by step instructions:

First, create a timestamp file:
$ touch timestamp

When you type
$ ls -l timestamp
you will see the file's modified time, which should be just a second ago.

Next up, you change any setting or configuration. It is recommended that you do one change at a time unless you know what you are doing. I am going to change the font size of the default terminal profile.

Then, look for files that have been modified after the timestamp file by
$ find / -type f -newer timestamp -not -path "/proc/*" -not -path "/run/*" -not -path "/dev/*" 2> /dev/null

The command is very long and intimidating at first glance. Let us break down the command and look at each option one by one:

find / command will search all files and folders in the root directory. Note that if you change the configuration that pertains to a specific user, the file is saved in the user directory, i.e., ~ or /home/username. In this case, you may want to type in find ~ instead.

-type f will search for files only, not directories; this is because the configuration or setting will be saved as a file.

-newer timestamp will only find those that have been modified after that of timestamp file, which we have created in the first step.

-not -path "/proc/*" option will exclude those in the /proc directory from the result; we are doing this because /proc directory contains process information, which change constantly, so we want to opt this directory out. Note that this option only pertains to find /, since find ~ will not search for /proc directory anyway.

-not -path "/run/*" option will exclude those in the /run directory from the result; /run directory contains run-time variable data. This directory may change regardless of the configuration change, so we will opt this directory out as well.

-not -path "/dev/*" option will exclude those in the /dev directory from the result. Note that it is extremely unlikely that the configuration change is saved in either /proc, /run, or /dev directories.

2> /dev/null will ignore any error messages, such as those that complain for permission denied. You may get rid of this option by using sudo. More on this later.

When you prompt the aforementioned command, you will get output something similar to
where it is obvious that the first file ~/.config/dconf/user is the configuration setting file that is responsible for terminal profile. Unfortunately, this file is not a simple plain-text configuration file, so it is a bit difficult to open up and read the file. However, you can try the following:

Open up the file with vim
$ vim ~/.conf/dconf/user

Within vim, search the text 'Monospace' by entering
You will most likely see a string Monospace, the default terminal font, within this file. As a matter of fact, this is actually the right file; you will see the font size in number right next to the string. I will cover this in more details in the later post. Quit vim by pressing ESC key and entering

Although in most cases, the configuration file should be readable by the user, it is not the case all the time. In this case, one will need to invoke sudo
$ sudo find / -type f -newer timestamp -not -path "/proc/*" -not -path "/run/*"

I will cover more details of this ~/.conf/dconf/user file in the later post.

No comments:

Post a Comment