Home / Alt manpages / termcap(5)

  • termcap(5)
  • File format
  • linux

Inspect and Maintain Legacy termcap Entries Safely

termcap is the terminal database format Unix used before terminfo, and this system still has to answer to it when an old program asks. You will check the entry selected by TERM, view it in termcap syntax, and learn where a legacy termcap file still fits on a modern Linux box. Allow about fifteen minutes; everything here is read-only until you deliberately choose to edit a database.

This guide follows the installed termcap(5) manual from Linux man-pages 6.7, shipped in Debian package manpages 6.7-2. The manual itself calls termcap obsolete and points new programs at terminfo. Treat that as a hard line: inspect termcap when an old program genuinely requires it, and do not introduce it into anything new without a compatibility reason.

1. Check the terminal name

Termcap is indexed by the TERM environment variable, so start there. This is an ordinary command and needs no elevated privileges:

$ printf 'TERM=%s\n' "$TERM"
TERM=dumb
$ command -v infocmp
/home/linuxbrew/.linuxbrew/bin/infocmp

Your terminal name will probably differ. Do not replace it with a name copied from another host unless that terminal really is what you are using: a wrong value can make a program pick escape sequences your terminal cannot decode.

Checkpoint

Write down the exact TERM value. The commands below use $TERM, so they follow whatever your current shell has set rather than assuming a particular emulator.

2. Inspect the modern terminfo entry

Most current systems store compiled terminal descriptions in terminfo, not termcap. With no format option, infocmp prints a source-like terminfo description. Add -1 to put one capability per line, which makes a long entry much easier to scan:

$ infocmp -1 "$TERM" | sed -n '1,24p'
#       Reconstructed via infocmp from file: .../d/dumb
dumb|80-column dumb tty,
        am,
        cols#80,
        bel=^G,
        cr=\r,
        cud1=\n,
        ind=\n,
        lines#24,
        ...

Exact entry and output depend on the host. Boolean capabilities come first, then numeric, then string. For example am means automatic margins, co#80 is termcap notation for 80 columns, and cl= would hold the clear-screen string. This is a description, not something you send to the terminal directly.

3. Convert the entry to termcap syntax

Use -C when an old tool wants termcap capability names and punctuation. Add -r to include non-standard capabilities too. This prints to standard output and changes no database:

$ infocmp -C -r -1 "$TERM" | sed -n '1,22p'
#       Reconstructed via infocmp from file: .../d/dumb
dumb|80-column dumb tty:\
        :am:\
        :co#80:\
        :bl=^G:\
        :cr=\r:\
        :do=\n:\
        :sf=\n:\
        ...

termcap entries use a colon between fields. Names before the first colon are separated by vertical bars, and a trailing backslash continues one logical entry across several physical lines. Boolean fields carry no value, numeric fields use #, strings use =. The escape sequences you see are data for a terminal library, not shell commands.

Tip

If an old program only needs one capability name, grep the generated output instead of hand-editing a file:

$ infocmp -C -r "$TERM" | grep -E '(^|:)co#|(^|:)li#|(^|:)cl='
        :co#80:\

Formatting varies. Control characters in particular can show up as readable escapes or as caret notation.

4. Understand the legacy file boundary

The Linux manual documents /etc/termcap as the ASCII master database, one logical entry per terminal, continuation lines indented by a tab. On this machine that path does not exist, which is normal for a terminfo-based system. An application that still needs termcap may use its own compatibility library or a separately configured database instead.

Warning

Do not create /etc/termcap just because a tutorial mentions it. A system-wide database change can alter the behaviour of every old application on the box and normally needs root. Before any edit, identify the program that actually reads the file, check its documentation, and take a backup. A malformed entry can affect every user of that database.

If someone hands you a termcap file to inspect, read it, do not execute it:

$ sed -n '1,80p' /path/to/termcap
$ grep -n '^xterm' /path/to/termcap

Swap in the real file path. Never treat an untrusted termcap file as a shell script: it holds escape sequences and terminal control data, which can have visible or disruptive effects on a terminal, but it is not a program.

5. Treat conversion as a compatibility check, not proof

The ncurses manual is upfront that termcap strings are less expressive than terminfo strings. infocmp -C converts most parameterised capabilities but can comment out anything it cannot represent. Treat the output as a useful starting point, never proof that the two databases are equivalent.

Only save generated output when you have a clear reason, and write to a new file so an existing compatibility file cannot get truncated by an accidental redirect:

$ umask 077
$ infocmp -C -r -1 "$TERM" > /tmp/termcap-entry.$$
$ test -s /tmp/termcap-entry.$$ && sed -n '1,12p' /tmp/termcap-entry.$$
$ rm -- /tmp/termcap-entry.$$

This temporary file holds terminal capability data and gets removed straight after inspection. If you adapt this for a persistent file, use a controlled destination and keep the original around until an old application has actually been tested against the new one. Do not shortcut with sudo infocmp ... > /etc/termcap: the shell performs the redirection before privilege escalation even runs, so you can overwrite a shared file in a way that is hard to undo.

6. Diagnose the common failures

If infocmp says a terminal type is unknown, check the spelling and the database search path before doing anything else:

$ printf 'TERM=%s\n' "$TERM"
$ infocmp -D
$ infocmp "$TERM"
infocmp: couldn't open terminfo file

That final line is an example failure, not the expected result: it means the selected name was not found anywhere ncurses searched. Do not fix it by inventing a termcap entry. Check whether TERMINFO or TERMINFO_DIRS points at an incomplete directory, and confirm the ncurses data package is actually installed.

If a program misbehaves after a terminal change, restore the previous TERM value or reconnect with the terminal's normal setup. If you changed a shared termcap file, restore the backup and restart the affected program; a running process may already have cached its terminal description.

Done means

  • Checked the active TERM. You looked instead of guessing a terminal name.
  • Read the terminfo entry. You inspected it with infocmp.
  • Converted, not trusted. You used infocmp -C for the legacy form and treated it as lossy.
  • Left the system alone. System-wide files stayed untouched unless an identified legacy application genuinely needed the edit.
  • Can spot a missing entry. You can diagnose a bad database path without running anything as root.