xterm Command: Tutorial & Examples
Terminal emulator for the X Window System
The xterm
command is a fundamental tool for Linux users who work within the X Window System environment. It provides a simple, yet powerful terminal emulator
that allows you to interact with the shell and run command-line applications graphically. This article details what xterm
is, why it is essential, its usage,
common parameters, and practical examples demonstrating how to customize and extend its functionality for effective command-line management within a graphical
interface.
What xterm Does
xterm
is a terminal emulator for the X Window System, meaning it creates a window on your graphical desktop where you can run a command-line shell like Bash.
Unlike virtual consoles (accessed via Ctrl+Alt+F1-F6), xterm
operates inside the graphical environment, enabling users to launch multiple terminal windows,
customize their appearance, and interact with graphical applications that require terminal input and output.
Within the xterm
window, you can execute any command-line program just as you would in a console terminal. It displays text output from commands, accepts
keyboard input, supports copy-pasting, and manages terminal control sequences to provide features like color, cursor movement, and screen clearing.
Why xterm Is Important
Despite the availability of many modern terminal emulators, xterm
remains important for several reasons:
Ubiquity and Compatibility: It is one of the oldest and most stable X terminal emulators, available on virtually all UNIX and Linux systems running X. This makes it a reliable fallback terminal.
Lightweight and Fast:
xterm
is minimalistic, consuming fewer resources than many modern terminal emulators, making it ideal for low-resource systems or remote X sessions.Configurability: It provides extensive configuration options through command-line parameters and resource files, allowing advanced users to tailor their terminal environment finely.
Debugging and Maintenance: Because of its simplicity and standardization,
xterm
is often used in troubleshooting graphical or terminal issues in an X environment.
How xterm Works
When you invoke xterm
, it creates a new window managed by the X server. This window runs the shell or command you specify, connecting the input and output
streams between the terminal window and the running process.
The terminal interprets control sequences sent by applications to perform actions such as moving the cursor, changing colors, or clearing parts of the screen.
xterm
supports various standards like VT100 and Tektronix 4014 emulations, making it compatible with many software tools.
Internally, xterm
manages:
Input Events: Keyboard and mouse events passed from the X server to the terminal and then to the shell or application.
Output Rendering: Drawing characters and graphics in the window using X drawing primitives.
Terminal Emulation: Parsing escape sequences to recreate the behavior of hardware terminals.
How to Use xterm
Basic usage of xterm
is straightforward. Simply type xterm
in an existing X session terminal or launch it from a graphical menu:
xterm
This command opens a new terminal window running the default shell (usually Bash). You can then interact with it like any other terminal.
You can also specify commands to run inside the xterm
window. For example, to run top
inside xterm
:
xterm -e top
The -e
option instructs xterm
to execute the specified command instead of launching the default shell. The terminal window will close when the command
finishes unless you keep it open explicitly.
Common Command Line Parameters
xterm
offers many options to customize its behavior. Some of the most commonly used parameters include:
-e command: Execute the specified command inside the terminal.
-geometry colsxrows+x+y: Set the size and position of the window. For example,
80x24+10+10
means 80 columns, 24 rows, positioned 10 pixels from left and top.-fn fontname: Use the specified font for text display.
-bg color: Set background color.
-fg color: Set foreground (text) color.
-title title: Set the window title.
-hold: Keep the window open after the command executed with
-e
ends.-iconic: Start the window minimized (iconified).
-boldFont fontname: Set font to use for bold text.
-fa fontname: Use a specific font via Xft (anti-aliased fonts).
-fb fontname: Use a specific bold font via Xft.
-rv: Reverse video (swap foreground and background colors).
Practical Examples Using xterm
Below are several examples demonstrating typical and advanced usage of xterm
.
Open a simple terminal window
xterm
This opens a new window with a shell prompt.
Open an xterm with custom size and position
xterm -geometry 100x40+200+100
Opens a window 100 columns wide and 40 rows tall, located 200 pixels from the left and 100 pixels from the top of the screen.
Run a command and keep the window open
xterm -hold -e ls -l /etc
This runs
ls -l /etc
inside the terminal and keeps the window open after showing the output.Set custom font and colors
xterm -fa 'Monospace' -fs 12 -bg black -fg green -title "My Terminal"
Opens an xterm window with the Monospace font at size 12, green text on a black background, and the title "My Terminal".
Run a long-running command like
top
xterm -e top
Opens a terminal window running the
top
process monitor.Start xterm iconified (minimized)
xterm -iconic
Use reverse video mode
xterm -rv
Execute a shell script inside xterm
xterm -hold -e /home/user/myscript.sh
Potential Problems and Pitfalls
While xterm
is stable, some issues may arise:
Font Issues: If fonts specified are not installed or recognized,
xterm
will fall back to defaults or may refuse to start. Usexlsfonts
to list available fonts.Color Compatibility: Some older terminals or applications might not support 256 colors or true color, causing display issues.
Window Size Limits: Specifying very large window sizes can cause errors or truncated displays.
Command Exit Behavior: Without the
-hold
option, windows running commands with-e
close immediately after the command finishes, which might surprise new users.X Server Connection:
xterm
requires a working X server. On headless or minimal systems, it won't work unless an X server or forwarding is set up.Locale and Encoding: Mismatched locales may cause incorrect character rendering.
Tips and Best Practices
Use the
-hold
option when running short commands with-e
to prevent the window from closing immediately.Customize fonts and colors via command line or X resources (e.g.,
.Xresources
or.Xdefaults
) for consistent appearance.Use the
-geometry
option to arrange multiplexterm
windows neatly on your desktop.Combine
xterm
with tools likescreen
ortmux
to manage terminal multiplexing within the window.Use
xterm
in remote sessions with X forwarding over SSH by enablingssh -X
, useful for graphical terminal access to remote servers.For scripting, use
xterm
with-e
to run commands or scripts in a separate terminal window.Use
Ctrl+LeftClick
orCtrl+RightClick
inside thexterm
window to access font size adjustments and other menus.
Scripting and Integration With Other Tools
xterm
can be incorporated into scripts to launch terminals running specific commands or monitoring tools. For example, a system administrator might create a
script that launches multiple xterm
windows monitoring different log files or system stats:
#!/bin/bash
xterm -title "Syslog" -hold -e tail -f /var/log/syslog &
xterm -title "Auth Log" -hold -e tail -f /var/log/auth.log &
xterm -title "Disk Usage" -hold -e watch df -h &
This script opens three terminal windows monitoring different logs and disk usage in real time.
Because xterm
accepts command-line options and can be controlled via X resources, it fits well in automation and monitoring workflows.
See Also
ssh
– Secure shell for remote terminal accessscreen
– Terminal multiplexer for managing multiple sessionstmux
– Another terminal multiplexer with advanced featuresbash
– Common shell used inside xterm/etc/X11/xorg.conf
– Configuration file for X server.Xresources
– User resource configuration for X applications including xterm- X Window System
ls
– List directory contentstop
– Task manager for Linux processes
Further Reading
- Linux for Hackers by Mark Reed (partner link)
- How Linux Works by Brian Ward (partner link)
- Linux for Beginners by Jason Cannon (partner link)
- Expert Linux Administration Guide by Vishal Rai (partner link)
As an Amazon Associate, I earn from qualifying purchases.