term (7) — Linux Manuals
The environment variable TERM should normally contain the type name of the terminal, console or display-device type you are using. This information is critical for all screen-oriented programs, including your editor and mailer.
A default TERM value will be set on a per-line basis by either /etc/inittab (e.g., System-V-like UNIXes) or /etc/ttys (BSD UNIXes). This will nearly always suffice for workstation and microcomputer consoles.
If you use a dialup line, the type of device attached to it may vary. Older UNIX systems pre-set a very dumb terminal type like «dumb» or «dialup» on dialup lines. Newer ones may pre-set «vt100», reflecting the prevalence of DEC VT100-compatible terminals and personal-computer emulators.
Modern telnets pass your TERM environment variable from the local side to the remote one. There can be problems if the remote terminfo or termcap entry for your type is not compatible with yours, but this situation is rare and can almost always be avoided by explicitly exporting «vt100» (assuming you are in fact using a VT100-superset console, terminal, or terminal emulator).
In any case, you are free to override the system TERM setting to your taste in your shell profile. The tset(1) utility may be of assistance; you can give it a set of rules for deducing or requesting a terminal type based on the tty device and baud rate.
Setting your own TERM value may also be useful if you have created a custom entry incorporating options (such as visual bell or reverse-video) which you wish to override the system default type for your line.
Terminal type descriptions are stored as files of capability data underneath /etc/terminfo. To browse a list of all terminal names recognized by the system, do
from your shell. These capability files are in a binary format optimized for retrieval speed (unlike the old text-based termcap format they replace); to examine an entry, you must use the infocmp(1) command. Invoke it as follows:
where entry_name is the name of the type you wish to examine (and the name of its capability file the subdirectory of /etc/terminfo named for its first letter). This command dumps a capability file in the text format described by terminfo(5).
The first line of a terminfo(5) description gives the names by which terminfo knows a terminal, separated by «|» (pipe-bar) characters with the last name field terminated by a comma. The first name field is the type’s primary name, and is the one to use when setting TERM. The last name field (if distinct from the first) is actually a description of the terminal type (it may contain blanks; the others must be single words). Name fields between the first and last (if present) are aliases for the terminal, usually historical names retained for compatibility.
There are some conventions for how to choose terminal primary names that help keep them informative and unique. Here is a step-by-step guide to naming terminals that also explains how to parse them:
First, choose a root name. The root will consist of a lower-case letter followed by up to seven lower-case letters or digits. You need to avoid using punctuation characters in root names, because they are used and interpreted as filenames and shell meta-characters (such as !, $, *, ?, etc.) embedded in them may cause odd and unhelpful behavior. The slash (/), or any other character that may be interpreted by anyone’s file system (\, $, [, ]), is especially dangerous (terminfo is platform-independent, and choosing names with special characters could someday make life difficult for users of a future port). The dot (.) character is relatively safe as long as there is at most one per root name; some historical terminfo names use it.
The root name for a PC-Unix console type should be the OS name, i.e., linux, bsdos, freebsd, netbsd. It should not be console or any other generic that might cause confusion in a multi-platform environment! If a model number follows, it should indicate either the OS release level or the console driver release level.
The root name for a terminal emulator (assuming it does not fit one of the standard ANSI or vt100 types) should be the program name or a readily recognizable abbreviation of it (i.e., versaterm, ctrm).
Following the root name, you may add any reasonable number of hyphen-separated feature suffixes. 2p Has two pages of memory. Likewise 4p, 8p, etc. mc Magic-cookie. Some terminals (notably older Wyses) can only support one attribute without magic-cookie lossage. Their base entry is usually paired with another that has this suffix and uses magic cookies to support multiple attributes. -am Enable auto-margin (right-margin wraparound). -m Mono mode — suppress color support. -na No arrow keys — termcap ignores arrow keys which are actually there on the terminal, so the user can use the arrow keys locally. -nam No auto-margin — suppress am capability. -nl No labels — suppress soft labels. -nsl No status line — suppress status line. -pp Has a printer port which is used. -rv Terminal in reverse video mode (black on white). -s Enable status line. -vb Use visible bell (flash) rather than beep. -w Wide; terminal is in 132-column mode.
Conventionally, if your terminal type is a variant intended to specify a line height, that suffix should go first. So, for a hypothetical FuBarCo model 2317 terminal in 30-line mode with reverse video, best form would be fubar-30-rv (rather than, say, «fubar-rv-30»).
Terminal types that are written not as standalone entries, but rather as components to be plugged into other entries via use capabilities, are distinguished by using embedded plus signs rather than dashes.
Commands which use a terminal type to control display often accept a -T option that accepts a terminal name argument. Such programs should fall back on the TERM environment variable when no -T option is specified.
PORTABILITY
For maximum compatibility with older System V UNIXes, names and aliases should be unique within the first 14 characters.
FILES
/etc/terminfo/?/* compiled terminal capability database /etc/inittab tty line initialization (AT&T-like UNIXes) /etc/ttys tty line initialization (BSD-like UNIXes)
Which terminal type am I using?
But if I use the dropdown menu «help» > «about» then it says gnome terminal 3.4.1.1 . Does this mean I am using just gnome-terminal? Or just xterm? Or is gnome-terminal an extension of xterm? I’m confused.
4 Answers 4
What is $TERM for?
The $TERM variable is for use by applications to take advantage of capabilities of that terminal.
For example, if a program wants to display colored text, it must first find out if the terminal you’re using supports colored text, and then if it does, how to do colored text.
The way this works is that the system keeps a library of known terminals and their capabilities. On most systems this is in /usr/share/terminfo (there’s also termcap, but it’s legacy not used much any more).
So let’s say you have a program that wants to display red text. It basically makes a call to the terminfo library that says «give me the sequence of bytes I have to send for red text for the xterm terminal«. Then it just takes those bytes and prints them out.
You can try this yourself by doing tput setf 4; echo hi . This will get the setf terminfo capability and pass it a parameter of 4 , which is the color you want.
Why gnome terminal lies about itself:
Now let’s say you have some shiny new terminal emulator that was just released, and the system’s terminfo library doesn’t have a definition for it yet. When your application goes to look up how to do something, it will fail because the terminal isn’t known.
The way your terminal gets around this is by lying about who it is. So your gnome terminal is saying «I’m xterm«.
Xterm is a very basic terminal that has been around since the dawn of X11, and thus most terminal emulators support what it supports. So by gnome terminal saying it’s an xterm, it’s more likely to have a definition in the terminfo library.
The downside to lying about your terminal type is that the terminal might actually support a lot more than xterm does (for example, many new terminals support 256 colors, while older terminals only supported 16). So you have a tradeoff, get more features, or have more compatibility. Most terminals will opt for more compatibility, and thus choose to advertise themselves as xterm .
If you want to override this, many terminals will offer some way of configuring the behavior. But you can also just do export TERM=gnome-terminal .
The TERM environment variable indicates the terminal type, not the terminal application. TERM has a specific purpose: it tells applications running in that terminal how to interact with the terminal.
Applications interact with terminals by writing escape sequences — sequences of characters that include nonprintable characters and have effects such as moving the cursor, erasing part of the screen, changing the current color, etc. In the old days, different brands of physical terminals had different sets of escape sequences. Therefore the operating system maintains a database of terminal types and their characteristics. The traditional database is termcap (“TERMinal CAPabilities”); many modern systems and applications have switched to terminfo. Both databases are indexed by the name of the terminal type, and applications query them using the terminal type name from the TERM environment variables.
Nowadays, most terminals use a standard set of escape sequences with a few common sets of extensions, so you won’t see many different values of TERM . Most GUI terminal emulators are compatible with xterm, the traditional X terminal (which is still used and maintained).
Terminal emulators that differ from xterm may add their own entry to the terminal database under their own name. However this doesn’t mesh well with remote shells. A program running on machine A but which is displaying on machine B, for example because it was launched through ssh from B to A, needs to query the terminal database on machine A. Remote login methods such as ssh carry over the TERM environment variable, but this is helpful only when B’s terminal database also has an entry for the value user on A. Therefore many terminal emulators stick to TERM=xterm which is pretty much universally known.
The differentiation between terminals by and large does not come from the way applications interact with them, but by the way the terminals interact with the user and fit in their environment. For example, Gnome Terminal looks good on Gnome and provides tabs and other niceties; Konsole looks good on KDE and provides tabs and other niceties; urxvt has a small memory requirement; Console2 runs on Windows; screen and tmux provide sessions that can be attached to different parent terminals; and so on. Since none of these features make a difference to applications running in the terminal, most terminal emulators use TERM=xterm .
To find out what terminal a shell is running in (assuming the shell is running directly in a terminal), look at the parent of the shell: