Simplifying file management with GNU Stow
Safely Stowed Away
Stow helps you manage custom configuration files across multiple users and computers, as well as organize your dotfiles.
When it comes to file management, keeping chaos in check is highly recommended. Stow [1], a lesser-known GNU file management tool, functions as a symlink farm manager that organizes various sets of software or data located in separate directories on the filesystem, making them appear to be installed in a single directory tree.
Stow was originally created to manage software compiled on the system, which typically ends up in the subdirectories of /usr/local/
. Stow is often used to install software globally across the system, but it also provides a clear-cut mechanism for managing configuration files and scripts in these installation's home directories. Stow can be considered the GNU project's official solution to keeping custom configuration files separate and distributing them to other systems.
When it comes to managing custom-compiled software, the software often does not come with an uninstall
target in the makefile or a similar mechanism to get rid of it when needed. As a result, this can lead to a time-consuming manual uninstall. For instance, you would need to use whereis <software>
to find out which subdirectories the software in question has been distributed to and then remove the files in each directory with rm -rf
. Stow can simplify this process.
Three Steps and a Prefix
Stow creates a separate directory named stow/
below /usr/local/
during the installation. You specify this when compiling an application in the first step of the typical three-step installation of the software below /usr/local/stow/
. Listing 1 shows you what the command looks like.
Listing 1
Creating stow/
Often CMake is used in the first step. With --prefix
as an additional instruction, all the software now ends up in stow/<software>.<version>
. To convert it to the directory structure provided for by the Filesystem Hierarchy Standard (FHS) [2], type
cd /usr/local/stow/
to change to the stow
directory, and trigger the creation of the symlinks to /usr/local/
with stow <software>
.
If you want to completely remove the software later on, all you need to do is type
stow -D <Software>
followed by
rm -rf <software>.<version>
After a package update, you can update the symlinks with --restow
.
In my lab, I used the sources of the recently published cURL 7.66.0 as an example. The software is installed using the commands from Listing 2. After this, the /usr/local/stow/curl-7.66.0
directories are located in the bin/
, include/
, lib/
, and share/
directories. If the prefix had not specified ../stow/curl-7.66.0/
as the installation location, the makefile would have distributed the program to these folders.
Listing 2
Installing curl-7.66.0
Symlink Redirection
To spoof the locations the system expects (Figure 1), you need to create symlinks from the /usr/local/stow/
directory with:
stow curl-7.66.0
Follow this up with ldconfig
to register new libraries with the system. If you now run ls -la
in /usr/local/include
, you will see the symlink to:
curl -> ../stow/curl-7.66.0/include/curl
The same applies to the other directories.
By installing software to a single directory and achieving FHS compliance through symlinks to the system, Stow resembles distributions such as NixOS or GoboLinux, which have long used a similar approach as a general solution for managing software.
Managing Dotfiles
Today, software is mainly installed using the package manager or it enters the system in the form of Flatpaks and Snaps. Over time, Stow has extended its application beyond its original purpose. This is reflected in the way the helper is implemented as a Perl script. In 2013, Stow's man page called the tool a "Software Package Installation Manager," while today it describes itself as a "Symlink Farm Manager" that offers extended application options for private use.
One extended application option includes managing dotfiles (the hidden configuration files in an installation's home directory called dotfiles because of the dot in front of their name). If you want to use these files or a collection of scripts that you use repeatedly on several computers, Stow can help.
One good example of this is the .bashrc
file. This configuration file goes into action every time you open a terminal. Among other things, it contains useful entries, such as the aliases you created for frequently used command sequences or instructions for a custom prompt display. My .bashrc
file has been in use for well over a decade, and I include it in every new installation.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.