HomeTechnologyLinuxManage your configuration files...

Manage your configuration files with GNU Stow

GNU Stow makes it easy to centrally manage the configuration files in your home directory. This allows you to easily bring it under version management or easily synchronize it with other systems. We give a brief introduction here.

Matt French

GNU Stow calls itself a “symlink farm manager” and was originally developed to keep a grip on self-installed software packages. However, it is also very suitable for managing and synchronizing the configuration files in your home directory.

GNU Stow is written in Perl and is therefore platform independent. It is available under the GPL3 open source license. You simply install it via the package manager of your Linux distribution or BSD system.

dot files

Traditionally in Unix-like environments, the personal configuration file of user applications resides in the root of the home directory. Here, the file name is made up of a period, followed by the name of the application, and usually followed by “rc”, such as “.bashrc” for the Bash configuration file. The dot at the beginning of the file name ensures that the file is “hidden”, when requesting a directory listing with “ls” it is not shown. The names of these configuration files all start with a dot, which is why they are often referred to as ‘dotfiles’.

The X Desktop Group (XDG) developed a new standard. This consists of a directory called “.config”, in the root of your home directory, containing a subdirectory per application, containing the configuration files. In addition, the XDG also describes the use of the “.local” directory in your home directory. Applications can also place files in their own sub-directory in this .local directory. For example, Midnight Commander (mc) saves the history here.

The result of all this is that your home directory contains your configuration files and the like spread over several places. With GNU Stow you bring all these files to one central place, GNU Stow ensures that the correct symbolic links (symlinks) are created, whether they are in the root of your home directory, or for example in ~/.config or in ~/ .local should come. The character “~” represents your home directory, so if your username is “jolanda”, then “~” represents “/home/jolanda”.

Packages

The use of GNU Stow is based on packages. To manage the dot files in your home directory, this means that you define a package for each application. For Bash you define the package “bash”, for w3m the package “w3m”, for the i3 window manager the package “i3”, and so on. Each package gets its own directory and within this directory you describe the path or paths and include the appropriate files.

You start by creating a directory for GNU Stow, we choose ~/.dotfiles. Then you create a directory for each package, so for example ~/.dotfiles/bash for Bash. Then move the relevant files from your home directory to this directory, such as “.bashrc”, which will become “~/.dotfiles/bash/.bashrc”.

Sometimes user applications first have a subdirectory in the home directory, containing the configuration files, such as w3m. This text browser uses ~/.w3m for the user files, such as “~/.w3m/config” and “~/.w3m/bookmark.html”. You solve this in the .dotfiles directory as follows. First, create another directory for the package, “~/.dotfiles/w3m”. Then move the entire ~/.w3m directory there, resulting in “~/.dotfiles/w3m/.w3m/config” and “~/.dotfiles/w3m/.w3m/bookmark.html”.

Now let’s get started with two user applications that follow the XDG standard, with their own directory in “~/.config”. For this example we choose the i3 window manager, with the configuration file “~/.config/i3/config”. First you create another directory for the package, “~/.dotfiles/i3”, and copy the path into it, so “~/.dotfiles/i3/.config/i3”. Now move the config file here, it will be “~/.dotfiles/i3/.config/i3/config”. Finally, delete ~/.config/i3.

You can also do this with the mc files. In the .dotfiles directory, create a subdirectory “mc”, containing “.config/mc” containing the “ini” file of mc, and “.local/share/mc/history”. Also now you move the relevant files.

See Listing 1 with the tree of the .dotfiles directory built up this way.

Create symlinks

Now go into the .dotfiles directory (cd ~/.dotfiles) and issue the command “stow *“. See the result of this action in your home directory,”cd” and “ls -la”.

You now have a symlink “.bashrc” in the home directory to .dotfiles/bash/.bashrc, and a symlink.w3m” to the directory “.dotfiles/w3m/.w3m”. Furthermore, GNU Stow has created a directory “.config” in the home directory, containing a symlink ”i3″ to “~/.dotfiles/i3/.config/i3” and a symlink “mc” to “~/.dotfiles /i3/.config/mc”. Furthermore, in the home directory there is a symlink “.local”, to “~/.dotfiles/mc/.local”. See also Listing 2.

GNU Stow is very smart about creating directories and that also allows us to have more packages that share part of a path with each other.

GNU Stow recognizes that two packages (i3 and mc) contain a directory “.config” and therefore first creates a subdirectory “~/.config” in our home directory, containing the symlinks for “.config/i3″ and “.config/mc“. GNU Stow also recognizes that only one package uses the “.local” subdirectory (mc), and therefore immediately creates a symlink for “~/.local”.

If you want to experiment further, you can undo the action by giving the command “stow -D *” in “~/.dotfiles”. Now the symlinks created by GNU Stow in your home directory are gone again.

Carefully

GNU Stow is very careful. If it needs to overwrite files or delete directories to execute the command, it refuses to execute the command. An exception to this are the files already under the management of GNU Stow.

This is why we moved the configuration files to this directory when building our stow directory (“~/.dotfiles”), not copying it.

Version management

By bringing all your dot files together in one central place, you make it easier to bring them under joint version management. A simple way to do this is – immediately after creating the “.dotfiles” directory – to first do “git init” in this directory. Only then do you place all the necessary packages in this directory. Next, you use “git add -A” to stage all the new files, then commit them to Git with “git commit -m ‘initial fill'”.

This puts all the files in the “dotfiles” directory under Git version control in one fell swoop. Changes to one or more of the files become visible with the command “git status”. You commit the change in Git with “git add -A” and “git commit -m ‘commit-message’”. You can then push this to a remote repository if desired.

You synchronize the dotfiles directory to another machine. You can do this for example with syncthing, rsync, or with “git clone”. After you have synchronized the directory, you put “stow *” in that directory, and you have your own familiar working environment again.

Dot filename

You choose the “–dotfiles” option if you prefer not to place hidden files in your dotfiles directory. You then start the file names with “dot-”, so for example “dot-bashrc”. then you call GNU Stow with –dotfiles, for example “stow –dotfiles *”. GNU Stow then creates a symlink with the correction name “.bashrc”.

Target directory

In the example above, GNU Stow used the home directory to build the directories and symlinks there. The reason for this is that GNU Stow uses the root directory of the stow directory as the target directory. However, this can be changed, using the option -t (“target”) you point to the directory that GNU Stow uses as the target directory. You also use this option if you don’t want your dotfiles directory in the root of your home directory, but somewhere else. Try it yourself!

- A word from our sponsors -

Most Popular

LEAVE A REPLY

Please enter your comment!
Please enter your name here

More from Author

An Unprecedented 190% Quantum Efficiency – New Material Could Drastically Increase the Efficiency of Solar Panels

Lehigh University researchers have created a revolutionary solar cell material with...

Even Brief Secondhand Smoke Exposure Increases Risk of Dangerous Heart Rhythm Disorder

New research indicates that even minimal exposure to secondhand smoke increases...

Neuronal Crossroads: Decoding Brain Development

New research uncovers the developmental pathways of inhibitory neurons in the...

Quantum Control Unlocked: Creating Resistance-Free Electron Channels

New research demonstrates control over quantum states that could revolutionize energy...

- A word from our sponsors -

Read Now

An Unprecedented 190% Quantum Efficiency – New Material Could Drastically Increase the Efficiency of Solar Panels

Lehigh University researchers have created a revolutionary solar cell material with up to 190% external quantum efficiency, pushing beyond conventional efficiency limits and showing great promise for enhancing future solar energy systems. Further development is required for practical application, supported by a U.S. Department of Energy grant.It...

Even Brief Secondhand Smoke Exposure Increases Risk of Dangerous Heart Rhythm Disorder

New research indicates that even minimal exposure to secondhand smoke increases the risk of atrial fibrillation, a common heart rhythm disorder. The study, involving over 400,000 adults from the UK Biobank, found a progressive increase in risk with longer exposure durations, regardless of the environment. The findings...

Neuronal Crossroads: Decoding Brain Development

New research uncovers the developmental pathways of inhibitory neurons in the brain, highlighting the roles of proteins like MEIS2 and DLX5 in neuron differentiation and the potential link to neurodevelopmental disorders through genetic mutations. Credit: SciTechDaily.comStudy reveals how proteins direct nerve cell precursors to turn into specialized...