These two files seem to have the same function. What is the difference between the two if any?
~/.Xdefaults is the older method of storing X resources. This file is re-read every time an Xlib program is started. If X11 is used over the network, the file must be present on the same filesystem as the programs.
~/.Xresources is newer. It is loaded with
xrdb into the
RESOURCE_MANAGER property of the X11 root window. Whenever any program looks up a resource, it is read straight from
If this property does not exist, Xlib falls back to the old method of reading
.Xdefaults on every program startup. Note that most distributions will load
~/.Xresources automatically if it is present, causing
.Xdefaults to be ignored even if you have never run
The advantage of the new method is that it's enough to call
xrdb once, and the resources will be available to any program running on this display, whether local or remote. (The name
~/.Xresources is only a convention – you can use
xrdb to load any file, even
Xlib Programming Manual P.441:
Prior to X11R2, X resource settings were read from .Xdefaults file in users home directory and optionally on whatever machine the X client was running on, so multiple files was hard to maintain.
Later on, xrdb program was made to store users resource settings from in .Xresources into the XA_RESOURCE_MANAGER property of the root window on the current X server, so all clients connected to the same server has access to them. If the user hasn't called xrdb to set the property, then .Xdefaults is read.
[...] the X resources are stored in two standard locations, depending on whether they apply to all screens or to a particular one:
- the RESOURCE_MANAGER property of the root window of screen 0
- the SCREEN_RESOURCES property of the root window of an arbitrary screen
It doesn't quite end at that.
- There also is the
$XENVIRONMENTvariable, which defaults to
~/.Xdefaults-hostnameif not set. This is used in the same way as
.Xdefaults, but is always read regardless of whether
RESOURCE_MANAGERis present. You can use
.Xdefaults-hostnamefiles to keep some settings machine-specific while using
xrdbfor the global ones.
Both items #4 and #5 listed below appear to be used only by pure Xlib programs – not GTK 3 or other toolkits.
The fourth location is the directory pointed to by the
$XAPPLRESDIRenvironment variable. (Oddly, if the variable is not set,
$HOMEis used as the default.) When a program is started, it looks if any of the following files exist (the file name being the same as the program's class name):
languageis derived from
$LC_CTYPEby stripping all but the first component; for example,
The fifth location is the system-wide "app-defaults" directories. Again, the app-defaults directories are checked on program startup if they have a file named after the program. For example, XTerm (on Arch Linux) uses:
The app-defaults files are usually installed into
/usr/sharealong with the program itself; administrator overrides would go to
Everything mentioned above is documented in great detail in the X.org toolkit documentation – article X Toolkit Intrinsics - C Language Interface, section Loading the Resource Database.
Unfortunately, I could not find any recent user guide that describes X resources, mostly because they are irrelevant in year 2012. But for historical (read: horribly out of date) information, you can read X Window System user's guide for X11 R3 and R4 of the X Window System section 9: Setting Resources (starting with page 181).