Linux xrdb command

Updated: 11/06/2021 by Computer Hope
xrdb command

On Unix-like operating systems, the xrdb command is the X window server resource database utility.

Description

If you are configuring the X windowing system for use on multiple clients, the xrdb program can be useful by helping you maintain multiple resource files in one unified resource database. The resources are stored on the X server, where they are accessible to any clients that connect to that server.

The xrdb command can run interactively from the command line, or it can be included in your .xinitrc or .xsession file so that it initializes resources at login.

Syntax

xrdb [-option ...] [file name]

The file name is optional, and specifies a file which contains the values of client variables ("resources") to be read. If no file name is specified, xrdb will expect these values to be provided via standard input. xrdb will overwrite its values with whatever you provide; so, if you run xrdb with no file name (starting it in interactive mode), and then enter no values, any values already loaded by your init scripts will be overwritten as valueless.

The values can be stored in a file named anything at all, but the file is commonly named .Xresources or .Xdefaults. .Xdefaults is a deprecated name in modern implementations; .Xresources is the preferred file name.

.Xresources is often loaded with xrdb automatically when xinit is called by your startup script. But if you'd like to make changes to the resource database manually, or change how xrdb is invoked in your scripts, you can invoke xrdb with these options.

Options

-help Display a brief help message.
-display display Specifies the X server to be used (see X for more information about multiple X displays). This option also specifies the screen to use for the -screen option.
-all This option indicates that any other operation specified should be performed on the screen-independent resource property (RESOURCE_MANAGER), and the screen-specific property (SCREEN_RESOURCES) on every screen of the display. For example, when used in conjunction with -query, the contents of all properties are output. For -load, -override and -merge, the input file is processed once for each screen. The resources which occur in common in the output for every screen are collected, and these are applied as the screen-independent resources. The remaining resources are applied for each per-screen property. This the default mode of operation.
-global Indicates that the operation should only be performed on the screen-independent RESOURCE_MANAGER property.
-screen This option indicates that the operation should only be performed on the SCREEN_RESOURCES property of the default screen of the display.
-screens This option indicates that the operation should be performed on the SCREEN_RESOURCES property of each screen of the display. For -load, -override and -merge, the input file is processed for each screen.
-n Show changes, but do not write them to the database. When specified, -n indicates changes to the specified properties (when used with -load, -override or -merge) or the resource file (when used with -edit) should be shown on the standard output, but not performed.
-quiet Quiet mode; specifically, any warnings about duplicate entries are not displayed.
-cpp file name xrdb uses a C preprocessor to interpret input; this option specifies the pathname of which C preprocessor program should be used. Although xrdb was designed to use the standard CPP, any program that acts as a filter and accepts the -D, -I, and -U options may be used.

This option should not be needed for typical users.
-nocpp This option indicates that xrdb should not run the input file through a preprocessor before loading it into properties.
-symbols Preprocessor-specific symbols will be printed onto the standard output. This option is useful for debugging purposes, and should not be needed for typical users.
-query Query the database for the current contents of the specified properties, and print them to standard output. This option lets you see what values are currently set.
-load This option indicates that the input should be loaded as the new value of the specified properties, replacing whatever was there (i.e., the old contents are removed). This option is the default action.
-override This option indicates that the input should be added to, instead of replacing, the current contents of the specified properties. If new entries overlap previous entries, the new ones overrides the previous values.
-merge This option indicates that the input should be merged and lexicographically sorted with, instead of replacing, the current contents of the specified properties.
-remove Indicates that the specified properties should be removed from the database.
-retain This option indicates that the server should be instructed not to reset if xrdb is the first client. This option should never be necessary under normal conditions since xdm and xinit always act as the first client.
-edit file name This option indicates that the contents of the specified properties should be edited into the given file, replacing any values already listed there. This option lets you put changes you have made to your defaults back into your resource file, preserving any comments or preprocessor lines.
-backup string This option specifies a suffix to be appended to the file name used with -edit to generate a backup file.
-Dname[=value] This option is passed through to the preprocessor and is used to define symbols for use with conditionals.
-Uname This option is passed through to the preprocessor and is used to remove any definitions of this symbol.
-Idirectory This option is passed through to the preprocessor and specifies a directory to search for files that are referenced with #include.

Syntax of an x resource

The general form of an X resource entry is:

name.Class.resource: value
  • The name is the name of the application, for instance "xterm" or "xscreensaver".
  • The class is the class of resources, such as "Dialog" or "Scrollbar". The name of a class often starts with an uppercase letter.
  • The resource is the name of the resource of the named application, in the resource class specified, to be changed. Resource names are often in "camel case", they start with a lowercase letter, and use uppercase letters in the name when there is a new word. For instance, "buttonFont".
  • The value is the value of the resource.

So, the following resource entry would set the resource "foreground", of the "Dialog" class of resources, of the application "xscreensaver":

xscreensaver.Dialog.foreground: #101010

With this resource value set, the dialog boxes of the xscreensaver application has the hexadecimal color value #101010.

Classes can also have sub-classes. For instance, the screensaver "Dialog" class has a sub-class "Button", that also takes a color value. To set the foreground resource to the same gray color, you could use the line:

xscreensaver.Dialog.Button.foreground: #101010

Using comments in your resource file

If a line in your resource file starts with an exclamation point "!", it will considered a comment and ignored by xrdb. So, you could include these lines in your resource file, for instance:

! My favorite xscreensaver dialog and button foreground colors: light gray
xscreensaver.Dialog.Button.foreground: #101010
screensaver.Dialog.foreground: #101010

Using wildcards

xrdb will interpret an asterisk ("*") as a wildcard, similar to using the asterisk when specifying file names in a shell. For instance, to set all xscreensaver "Dialog" resources to the same value, you could use the line:

xscreenaver*Dialog*: #101010

...or, to set the "Dialog" resources for every application:

*Dialog*: #101010

Examples of typical resources

Xft, the application which controls the rendering of fonts in X, can be configured with the following standard resources values:

Xft.dpi:        96
Xft.antialias:  true
Xft.rgba:       rgb
Xft.hinting:    true
Xft.hintstyle:  hintslight

xterm is the default X terminal emulator. Typical resource values for xterm include:

xterm*VT100.geometry:     80x25
xterm*faceName:           Courier:style=Regular:size=10
xterm*dynamicColors:      true
xterm*utf8:               2
xterm*eightBitInput:      true
xterm*saveLines:          512
xterm*scrollKey:          true
xterm*scrollTtyOutput:    false
xterm*scrollBar:          true
xterm*rightScrollBar:     true
xterm*jumpScroll:         true
xterm*multiScroll:        true
xterm*toolBar:            false

You can find the names of additional xterm resources and their values in our xterm documentation. In general, when configuring an X application's resources, it's a good idea to consult the application's man page for details.

Examples

xrdb

Open the server resource database utility in interactive mode. Values can be entered manually, and you can enter Ctrl-D when you are finished to be returned to the command line. If you enter nothing, any values already stored in the database will be removed.

Entering the values manually is the least-convenient way to access the resource database, and it's easy to make a typo. It's more common is to load values from a resource file, as in the next example.

xrdb -load ~/.Xresources

Load the file .Xresources in your home directory and write the values contained in it to the database. This command is often performed automatically when you start an X session, but this command will force a re-load of the resource values contained in the file, overwriting any other values stored in the database.

xrdb -query

Query the resource database to see what variables and values are currently set. Output resembles the following sample contents of an X resources file:

 *dialog*value*background: white
 *Dialog*Label*font:    -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*
 *MenuButton*font:      -adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*
 *MenuButton*background:        grey80
 *MenuButton*foreground:        black
 *Label.font:           -adobe-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*
 *Label*shadowWidth:    1
 *SmeBSB.font:          -adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*
 *SimpleMenu*font:      -adobe-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*
 *OptionMenu*font:      -adobe-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*
 *Command.font:         -linotype-helvetica-bold-r-narrow-*-12-*-*-*-*-*-*-*
 *Toggle.font:          -adobe-helvetica-bold-o-*-*-12-*-*-*-*-*-*-*
 *Form.background:      grey70
 *TransientShell*Dialog.background: grey70
 *Scrollbar.Foreground: grey80
 *Scrollbar.Background: grey50
 *Scrollbar*cursorName: top_left_arrow
 *Scrollbar*width:      16
 *shapeStyle:           Rectangle
 *XlwMenu.shadowThickness: 1
 *shadowWidth:          1
 xterm*scrollbar.background: grey40
 xterm*foreground: grey90
 xterm*background: grey25
 xterm*cursorColor: white
 xterm*visualbell: on
 rxvt*color12: steelblue
 rxvt*color15: white
 rxvt*color9: rgb:ff/7f/5f
 rxvt*foreground: grey90
 rxvt*background: grey10
 rxvt*cursorColor: white
 rxvt*font: lucidasanstypewriter-12
 rxvt*loginShell: false
 rxvt*saveLines: 1024
 rxvt*title: shell
 rxvt*geometry: 80x2
 xman*topBox: false
 xman*background: lightsteelblue
 xman*foreground: black
 xcalc*Command.font: -adobe-helvetica-bold-r-*-*-10-*-*-*-*-*-*-*
 xcalc*customization: -color
xrdb -merge my-xr-values

Merge the values listed in the file my-xr-values with any resource values currently stored in the database. This command is an alternative to overwriting all values with -load, for instance.

You could also use the -merge option without a file name, in which case you could manually enter a value (or values) and your entry would be merged with values already in the database. For instance, if you run

xrdb -merge

...and then type:

xterm.AllowBoldFonts.allowBoldFonts: true

...and then press Ctrl+D to terminate the entry, your resource database would store that value to the database, without removing any previous values stored. Any subsequent xterm sessions would use this value, and display bold font faces if called for.

startx — Start an X Window System session.
X — Executable of the X Window System.
xinit — The initializer of the X Window System.