Everything You Need to Know About Setting X Resources in Linux

These days, most Linux graphical programs use menus or configuration files in your home directory to store settings (many programs use both), but there is an older format for configurations that you should be aware of.

Some programs use an unusual format, known as X resources. It might sound intimidating, but it’s easy to set up.

4

What Are X Resources?

X resources is a method of configuration used by programs built with the original X toolkit. These programs are pretty old, but some of them are still in use, such as the xterm and rxvt terminal emulators.

The main reason you would want to learn how to set X resources is to change things in these apps, such as the background and foreground colors.

LinuxTagPageHeader

X resources follow a syntax of an X client, aperiod (.)orasterisk (*), and an attribute, acolon(:), followed by a whitespace and the value. The value can be a Boolean, True or False, a string, or a number.

The asterisk functions as a wildcard, similar to the shell. This is because different elements might have similarly-named attributes, such as a background color.

Mouse pointer over settings button

For example, to enable scrollbars on xterm:

How to Set X Resources From the Command Line

To change an app’s settings on a one-time basis, it’s possible to just use the command line. Many original X apps have command-line options that you can set directly. For example, the urxvt terminal emulator has-bgand-fgoptions to change the background and foreground.

To see what options are available, check the program’s manpage.

Oclock background colors being set with command line options.

The simplest solution for setting options you want to use later is to use a shell alias with these options and put it in your shell’s startup file, such as your.zshrcor.bashrc.

You can specify X resources in X resource format using the-xrmoption:

Debian with .Xresources file and urxvt running

The .Xresources File

If you want to change the settings for an X toolkit app every time you run it, use the.Xresourcesfile. This is a file that will live in your home directory, similar to your other configuration files like your.bashrc.

To create it, just open it in your favorite text editor. When you’re finished, save it.

If, like on most modern Linux desktops, you log in with a graphical display manager, it will read this file automatically. You should then be able to call up any older X program from the menu or the command line, and it should have the settings you chose.

Using xrdb to Modify .Xresources

If you startX without a display manager, you can use .Xresources by loading it in with xrdb.

xrdb is a program that can load X resources into the X server from the command line. xrdb was originally written when it was more common to run X11 programs off of networked servers.

xrdb allowed X resources to work with remote programs as well as clients running off of the local machine. xrdb loads resources into the X server so that clients can still use the user’s local settings, whether on the same machine or running over a network.

The xrdb program will load in any file that contains X resources settings with a command-line argument:

Put this line in your .xinitrc:

If you make changes to your .Xresources file, you can load it with xrdb to have them take effect immediately without having to restart X.

xrdb is typically installed by default with the X server, but if for some reason it isn’t you’re able to use your distro’s package manager.

For example, on Debian and Ubuntu:

On Arch Linux:

To install on Fedora and RHEL:

Now You Know About X Resources

With X resources, you can customize older X apps and have them look and work the way you want. These apps are based on the original X toolkit, but what is a toolkit? Toolkits are important for defining the look and feel of Linux apps.

The graphical interface you view on your Linux desktop is courtesy of GUI toolkits. Here’s everything you need to know about GUI frameworks on Linux.

I gripped my chair the entire time—and then kept thinking about it when the screen turned off.

These are the best free movies I found on Tubi, but there are heaps more for you to search through.

You’ve been quoting these famous films wrong all along!

My iPhone does it all, but I still need my dumb phone.

Don’t let someone else take over your phone number.

Technology Explained

PC & Mobile