Choose and Copy an X11 Font Name with xfontsel
You will finish with the full X Logical Font Description (XLFD) name of a font selected from the fonts known to your X server. xfontsel gives you a visual sample, lets you narrow the list with a pattern, and can copy the result through X's PRIMARY selection.
The route
Jump straight to the step you need, or tick off Done means at the end.
The examples match xfontsel 1.1.0 from x11-utils 7.7+6build2, installed on this machine. Allow about ten minutes. You need a running X display, the xfontsel command, and an X application in which you can paste the result. This is an ordinary user task: it does not need sudo.
Checkpoint
The useful outcome is a font name copied from the running window, not merely a successful process launch.
1. Check the installed command and its display
Confirm that the package is installed and that your shell knows where the executable is:
$ command -v xfontsel
/usr/bin/xfontsel
$ dpkg-query -W -f='${Package} ${Version}\n' x11-utils
x11-utils 7.7+6build2
$ printf 'display: %s\n' "${DISPLAY:-unset}"
display: :0
Your package revision and display value can differ. If DISPLAY is unset, or the command reports that it cannot open the display, run it from the graphical session that owns the X server. Do not try to repair an X connection by adding sudo; root may have a different display authorisation and still cannot make a missing server appear.
2. Start with a narrow font pattern
Without a pattern, xfontsel makes every font with a 14-part XLFD name selectable. That can produce a very large set of menus. A pattern limits the initial choices. The pattern is passed to the X server, while the shell handles characters such as *, so quote it:
$ xfontsel -pattern '*-m-*'
This requests names containing m in the field position represented by the pattern. The manual gives this form as a useful way to select a subset of monospaced fonts, but the result depends on the fonts installed and registered with your X server. The command opens a window and stays running until you activate its quit control.
Other useful starting points are partial or complete XLFD names, for example:
$ xfontsel -pattern '*medium*'
$ xfontsel -pattern '-*-*-medium-*-*-*-*-*-*-*-*-*-*-*'
Do not leave the wildcard unquoted. In a directory containing matching file names, the shell could expand *-m-* before xfontsel sees it, producing a different argument or an error.
Checkpoint
You should see the xfontsel window and a row of XLFD fields. If the window is nearly incomprehensible and a warning mentions a missing app-defaults file, check that /etc/X11/app-defaults/XFontSel is present. The installed program relies on that resource file for much of its interface.
3. Refine the XLFD fields
Click a field name to open its menu. Each field represents one part of the font name. Earlier choices constrain later menus, so an entry may be unavailable or absent after you choose another field.
To widen the choices again, choose the * entry in the field that is restricting them. This is a common distraction trap: an empty-looking menu does not necessarily mean that the X server has no fonts. It can mean that a previous field combination has no matches.
Keep the sample visible while changing fields. A field change updates the displayed sample when a matching font can be loaded. If a broad pattern produced an odd initial sample or a name that does not seem to match, choose a new value in one of the fields. The manual records this as a limitation of ambiguous patterns, not as evidence that the font file has been damaged.
For a scalable font, the server can report zero in the pixel-size, point-size and average-width fields. Those zero values leave the size implementation-dependent. If you need a particular size, start xfontsel with -scaled:
$ xfontsel -pattern '*-m-*' -scaled
The scaled mode adds selectable pixel and point sizes. It does not install a font or alter the server's font catalogue. The average-width menu can be unwieldy, so change it only when you have a specific reason to alter the font's horizontal scaling.
4. Copy the selected font name
When the sample and fields show the font you want, activate the select widget. xfontsel places the selected name in both the PRIMARY text selection and the PRIMARY_FONT selection. On X, this is normally pasted with the middle pointer button, rather than with a clipboard shortcut.
Test the hand-off in another X application. An xterm is convenient if it is available:
$ xterm &
Click in the new terminal and paste with the middle pointer button. The exact text will depend on your choices, but it should be a complete XLFD-style name beginning and ending with the values shown in xfontsel's fields. If you activate select again while it is highlighted, xfontsel releases ownership of the selection. Select it once more if you need to make the name available again.
There is no persistent state to undo here. Closing xfontsel ends the process. If another X application claims PRIMARY, xfontsel's select indicator de-highlights and its previous selection is no longer available through PRIMARY.
5. Print the name when quitting
If you want a shell-capturable result rather than an X selection, add -print. xfontsel writes the selected font specifier to standard output when you activate its quit control:
$ xfontsel -pattern '*-m-*' -print
# choose fields, then activate select if you also want PRIMARY
# activate quit in the xfontsel window
-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso10646-1
The displayed font name is host-dependent, and the sample line above is representative rather than a promised result. Redirecting output changes no system configuration, but avoid overwriting a useful file with an unreviewed shell redirection. Use a new destination if you want to keep the value:
$ xfontsel -pattern '*-m-*' -print > selected-font.txt
Do not expect the file to contain anything until you quit through the xfontsel window. If the file is empty, return to the window, make sure a font is selected, and activate quit. If you need a sample string for a non-default encoding, -sample, -sample16 and -sampleUCS change the text shown in the window; they do not change the font name that -print emits.
6. Diagnose a font that will not load
First check that the fields still describe a matching font. Select * in a restrictive field, then choose a value again. A pattern with too many wildcards can also lead to an ambiguous initial selection. Conversely, a very specific pattern can legitimately match nothing on this server.
If menus appear before xfontsel has finished parsing the server's font names, the manual says a request can produce a missing-menu message on standard error. Wait for parsing to finish and retry the menu. If the problem persists, close and relaunch the program; this does not change the font catalogue.
Remember that xfontsel examines the fonts known to the current X server. It does not search arbitrary font files, install fonts, or configure an application permanently. A font name copied from one server may not exist on another server, even if both machines run the same desktop environment.
Done means
xfontselopened on the intended X display without elevated privileges.- The initial list was narrowed with a quoted XLFD pattern when the full catalogue was distracting.
- You changed fields until the sample and complete font name matched your requirement.
- You copied the name through PRIMARY or printed it with
-printand checked the result. - You know that scaled sizes are optional, host-dependent, and not a persistent font installation.
- No system files, font catalogue, service, or user configuration was changed.