These two files seem to have the same function. What is the difference between the two if any?

1 Answer 1


~/.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 from RESOURCE_MANAGER without touching any files.

If the RESOURCE_MANAGER property does not exist, Xlib falls back to the old method of reading ~/.Xdefaults on every program startup. But note that most distributions will load ~/.Xresources automatically if it is present, which means the property will always exist and therefore ~/.Xdefaults will always be ignored even if you have never run xrdb yourself.

(You can use xprop -root to peek at the X root window's properties.)

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 ~/.Xdefaults.)

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.

(Note: XA_RESOURCE_MANAGER is an Xlib C macro that references a built-in atom, but the atom's actual name (for XInternAtom) is just RESOURCE_MANAGER.)


[...] 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

Additional files

It doesn't quite end at that.

  • There also is the $XENVIRONMENT variable, which defaults to ~/.Xdefaults-hostname if not set. This is read directly by programs, similar to .Xdefaults itself, but is always read regardless of whether RESOURCE_MANAGER is present or not. You can use .Xdefaults-hostname files to keep some settings machine-specific while using xrdb for 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 $XAPPLRESDIR environment variable. (Oddly, if the variable is not set, $HOME is 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):

    • $XAPPLRESDIR/language/XTerm

    (language is derived from $LC_CTYPE by stripping all but the first component; for example, en_US.utf-8en.)

  • 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:

    • /etc/X11/$LC_CTYPE/app-defaults/XTerm
    • /etc/X11/language/app-defaults/XTerm
    • /etc/X11/app-defaults/XTerm
    • /usr/share/X11/$LC_CTYPE/app-defaults/XTerm
    • /usr/share/X11/language/app-defaults/XTerm
    • /usr/share/X11/app-defaults/XTerm

    The app-defaults files are usually installed into /usr/share along with the program itself; administrator overrides would go to /etc.

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).

  • Great answer, but it should be noted that not all implementations follow the rules correctly. For instance, I remember SunOS 4 and Solaris 6 apps would not pick up .Xdefaults changes unless I explicitly ran "xrdb" afterward. There can also be some weirdness when the app and the X server are running on different hosts. Some apps read the local file and some read the database from the X server.
    – David C.
    Sep 17, 2014 at 15:30
  • 1
    @DavidC.: That Xdefaults behavior is following the rules described above. If xrdb has ever been run for this X display since login – that is, if the X root property exists – then xlib will not use .Xdefaults at all anymore. Sep 17, 2014 at 18:17
  • 1
    That makes sense. But there are still many apparently-borken apps which will read the contents of ~/.Xresources and ignore the xrdb database. Which can be really annoying if you slogin to a different host (that has a different .Xresources) and find that the app isn't displaying its contents the way it does when run locally.
    – David C.
    Sep 17, 2014 at 20:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .