7. X and the Command Line

What would a Unix-like operating system be without a command line interface? The command line can be useful, and is readily available with X. In fact, for many it is an integral part of their X working environment.

Any X program can be started directly from the command line just by typing the program name at a shell prompt in an xterm, or other terminal window. Most applications will have a very rich set of command line "options", such as background color, font, geometry (screen placement), etc, etc. Command line options over-ride compiled in defaults, or other system enabled "resources".

Many traditional X programs will use the same basic names for command line options. All applications written using the MIT X Toolkit Intrinsics (Xt) (such as those included with XFree86) automatically accept the following options. Some non-Xt applications also use these, or something similar. For instance, "geometry" is close to a universally accepted option.

-display [host]:display[.screen]

This option specifies the X server display to use. This is often used where applications are run on one system, and displayed on another. The application needs to know where to display. This is sometimes also accomplished by setting the "$DISPLAY" variable, which uses the same syntax.

-geometry geometry

The initial size and location of the window, in a format such as width x height +horz_offset +vert_offset or +horz_offset -vert_offset. Note that if you put in a negative horizontal or vertical offset, the window will be placed counting backward from the right or the bottom of the screen, respectively, instead of from the top left corner.

-font fontname

The font to use for displaying the text in your window (see font section below).

-bg color

The color to use for the window background. Typically this is a "color name" (see below).

-fg color

The color to use for the window foreground (i.e. fonts, etc).

-name resource-name

Useful for specifying the name under which the resources for this application will be found (e.g. as specified in .Xdefaults). This is useful to distinguish between invocations of the same application. For example, two xterms can be "named" differently so that they may inherit different resources based upon the specified names in the resource database.

-title string

This is the title to be used for the window on your display, generally used by the Window Manager to put a descriptive title at the top of the window. Not to be confused with the "-name" option.


Open window in an iconified state.

-xrm resource-string

This option specifies a resource name and value to override any defaults that may already be set (i.e. via .Xresources or similar). Also useful for setting X resources that do not have explicit command line options. For example, the command line "xterm -xrm xterm*background: blue &" is functionally the same as "xterm -bg blue &".

These are the most noteworthy. There are others. Many programs will have their own additional options that are application specific. Many newer applications today don't necessarily adhere to the Xt standards, and will use their own options, or those provided by their respective toolkit. If nothing else, man pages are a good reference for command syntax, and are your friends here. Or, the application will have a "--usage" or "--help" command line switch to list available options:

 $ gnome-terminal --usage
 Usage: gnome-terminal [-?] [--disable-sound] [--enable-sound]
   [--espeaker=HOSTNAME:PORT] [--version] [--usage] [--gdk-debug=FLAGS]
   [--gdk-no-debug=FLAGS] [--display=DISPLAY] [--sync] [--no-xshm]
   [--name=NAME] [--class=CLASS] [--gxid_host=HOST] [--gxid_port=PORT]
   [--xim-preedit=STYLE] [--xim-status=STYLE] [--gtk-debug=FLAGS]
   [--gtk-no-debug=FLAGS] [--g-fatal-warnings] [--gtk-module=MODULE]
   [--disable-crash-dialog] [--sm-client-id=ID] [--sm-config-prefix=PREFIX]
   [--sm-disable] [--tclass=TCLASS] [--font=FONT] [--nologin] [--login]
   [--geometry=GEOMETRY] [-e COMMAND] [-x COMMAND] [--foreground=COLOR]
   [--background=COLOR] [--solid] [--pixmap=PIXMAP] [--bgscroll]
   [--bgnoscroll] [--shaded] [--noshaded] [--transparent] [--utmp]
   [--noutmp] [--wtmp] [--nowtmp] [--lastlog] [--nolastlog] [-t TITLE]
   [--icon=ICON] [--termname=TERMNAME] [--start-factory-server]


7.1. xterm and friends

Sooner or later, most of us need to access the "command line" for one reason or another. For some, this might even be a common way of working in X. In addition to being able to launch X applications from the command prompt, there is also a wealth of programs that run in "text mode" for Linux.

This is possible via "terminal emulators" such as xterm. The closest counterpart from Microsoft is the so-called DOS-box, which is child's play by comparison. Linux terminals support color, full mouse copy/paste (and some wheeled mice), pseudo-transparency and pixmap backgrounds, scrollbars, menus and generally a slew of other features. While xterm is the best known such terminal emulator, there are many similar programs. To name a few: Eterm, rxvt, aterm, konsole (KDE) and gnome-terminal.

In typical usage, when a terminal emulator window is opened, a shell is started for the user to interact with. The default for essentially all Linuxes, is the bash shell. So when all is said and done, the user is interacting with X, the terminal, and the shell all at once. Each may have it's own influence. For example, how keystrokes are handled since they move from hardware to X server to terminal to the shell and finally echoed back to the user.

Quick and easy terminal configuration is done via the "$TERM" variable, which is typically set in one of the user's shell configuration files. Or the terminal itself will have a compiled in default. The default value for this is most often "xterm":

 $ echo $TERM


Normally this is sufficient, as your vendor has already set this up in a reasonable way. The "$TERM" variable is actually a reference to an entry in the "termcap" database (man termcap), which is typically installed as /etc/termcap. Unless you are doing something really unusual, you probably won't need to change this. Some additional terminal configuration can be done with the stty command (see man page). Terminal configuration is really beyond the scope of this document.

The terminal application itself (e.g. xterm) will also have various configuration options. Permanent settings are best stored in a ~/.Xdefaults or similar file for those applications that support this. Generally speaking, applications with a GUI configuration (such as gnome-terminal), will be configured by their own menu driven configuration instead.

Also, you are interacting with the shell too, which can have it's own impact, particularly on how keystrokes are handled at the shell prompt. For bash, this can be adjusted in ~/.inputrc. Again, this is beyond the scope of this document, but check with either local or on-line bash (or other shell) references.

Terminal emulators like xterm require a monospaced font. So forget about TrueType or Type 1 fonts.