termios(3type)
π NAME π
termios β terminal input/output settings. This is the termios(3type) page, bestie, and it's literally all about how your terminal talks to your program. No cap.
π LIBRARY π
Standard C library (libc)
β¨ SYNOPSIS β¨
#include <termios.h>
struct termios {
// At least these members, in no particular order
tcflag_t c_iflag;
tcflag_t c_oflag;
tcflag_t c_cflag;
tcflag_t c_lflag;
cc_t c_cc[NCCS];
};
πΈ DESCRIPTION πΈ
.c_iflagβ Input modes..c_oflagβ Output modes..c_cflagβ Control modes..c_lflagβ Local modes..c_ccβ Special characters.
The values you're allowed to assign to these fields are described below. For the first four bit-mask fields, some associated flags only show up if a specific feature test macro is defined (see feature_test_macros(7)), and that's noted in brackets ([]). It's giving conditional visibility, fr fr.
In the descriptions below, "not in POSIX" means the value isn't specified in POSIX.1-2001, and "XSI" means it is specified in POSIX.1-2001 as part of the XSI extension. Slay.
The symbolic subscript values below are all different, except that VTIME, VMIN may have the same value as VEOL, VEOF, respectively. In noncanonical mode, the special character meaning gets replaced by the timeout meaning. For an explanation of VMIN and VTIME, see the description of noncanonical mode below. Iconic behavior, honestly.
π¦ .c_iflag flag constants π¦
IGNBRKβ IgnoreBREAKcondition on input.BRKINTβ IfIGNBRKis set, aBREAKis ignored. If it is not set butBRKINTis set, then aBREAKcauses the input and output queues to be flushed, and if the terminal is the controlling terminal of a foreground process group, it will cause aSIGINTto be sent to this foreground process group. When neitherIGNBRKnorBRKINTare set, aBREAKreads as a null byte ('\0'), except whenPARMRKis set, in which case it reads as the sequence\377 \0 \0.IGNPARβ Ignore framing errors and parity errors.PARMRKβ If this bit is set, input bytes with parity or framing errors are marked when passed to the program. This bit is meaningful only whenINPCKis set andIGNPARis not set. The way erroneous bytes are marked is with two preceding bytes,\377and\0. Thus, the program actually reads three bytes for one erroneous byte received from the terminal. If a valid byte has the value\377, andISTRIP(see below) is not set, the program might confuse it with the prefix that marks a parity error. Therefore, a valid byte\377is passed to the program as two bytes,\377 \377, in this case.
If neither IGNPAR nor PARMRK is set, read a character with a parity error or framing error as \0.
INPCKβ Enable input parity checking.ISTRIPβ Strip off eighth bit.INLCRβ Translate NL to CR on input.IGNCRβ Ignore carriage return on input.ICRNLβ Translate carriage return to newline on input (unlessIGNCRis set).IUCLCβ (not in POSIX) Map uppercase characters to lowercase on input.IXONβ Enable XON/XOFF flow control on output.IXANYβ (XSI) Typing any character will restart stopped output. (The default is to allow just the START character to restart output.)IXOFFβ Enable XON/XOFF flow control on input.IMAXBELβ (not in POSIX) Ring bell when input queue is full. Linux does not implement this bit, and acts as if it is always set.IUTF8(since Linux 2.6.4) β (not in POSIX) Input is UTF8; this allows character-erase to be correctly performed in cooked mode.
π .c_oflag flag constants π
OPOSTβ Enable implementation-defined output processing.OLCUCβ (not in POSIX) Map lowercase characters to uppercase on output.ONLCRβ (XSI) Map NL to CR-NL on output.OCRNLβ Map CR to NL on output.ONOCRβ Don't output CR at column 0.ONLRETβ The NL character is assumed to do the carriage-return function; the kernel's idea of the current column is set to 0 after both NL and CR.OFILLβ Send fill characters for a delay, rather than using a timed delay.OFDELβ Fill character is ASCII DEL (0177). If unset, fill character is ASCII NUL ('\0'). (Not implemented on Linux.)NLDLYβ Newline delay mask. Values areNL0andNL1. [[requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE]]CRDLYβ Carriage return delay mask. Values areCR0,CR1,CR2, orCR3. [[requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE]]TABDLYβ Horizontal tab delay mask. Values areTAB0,TAB1,TAB2,TAB3(orXTABS, but see the BUGS section). A value ofTAB3, that is,XTABS, expands tabs to spaces (with tab stops every eight columns). [[requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE]]BSDLYβ Backspace delay mask. Values areBS0orBS1. (Has never been implemented.) [[requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE]]VTDLYβ Vertical tab delay mask. Values areVT0orVT1.FFDLYβ Form feed delay mask. Values areFF0orFF1. [[requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE]]
π .c_cflag flag constants π
CBAUDβ (not in POSIX) Baud speed mask (4+1 bits). [[requires _BSD_SOURCE or _SVID_SOURCE]]CBAUDEXβ (not in POSIX) Extra baud speed mask (1 bit), included inCBAUD. [[requires _BSD_SOURCE or _SVID_SOURCE]]
(POSIX says that the baud speed is stored in the termios structure without specifying where precisely, and provides cfgetispeed() and cfsetispeed() for getting at it. Some systems use bits selected by CBAUD in .c_cflag, other systems use separate fields, for example, sg_ispeed and sg_ospeed.)
CSIZEβ Character size mask. Values areCS5,CS6,CS7, orCS8.CSTOPBβ Set two stop bits, rather than one.CREADβ Enable receiver.PARENBβ Enable parity generation on output and parity checking for input.PARODDβ If set, then parity for input and output is odd; otherwise even parity is used.HUPCLβ Lower modem control lines after last process closes the device (hang up).CLOCALβ Ignore modem control lines.LOBLKβ (not in POSIX) Block output from a noncurrent shell layer. For use byshl(shell layers). (Not implemented on Linux.)CIBAUDβ (not in POSIX) Mask for input speeds. The values for theCIBAUDbits are the same as the values for theCBAUDbits, shifted leftIBSHIFTbits. [[requires _BSD_SOURCE or _SVID_SOURCE]] (Not implemented in glibc, supported on Linux viaTCGET*andTCSET*ioctls; seeioctl_tty(2))CMSPARβ (not in POSIX) Use "stick" (mark/space) parity (supported on certain serial devices): ifPARODDis set, the parity bit is always 1; ifPARODDis not set, then the parity bit is always 0. [[requires _BSD_SOURCE or _SVID_SOURCE]]CRTSCTSβ (not in POSIX) Enable RTS/CTS (hardware) flow control. [[requires _BSD_SOURCE or _SVID_SOURCE]]
π .c_lflag flag constants π
ISIGβ When any of the charactersINTR,QUIT,SUSP, orDSUSPare received, generate the corresponding signal.ICANONβ Enable canonical mode (described below).XCASEβ (not in POSIX; not supported under Linux) IfICANONis also set, terminal is uppercase only. Input is converted to lowercase, except for characters preceded by\. On output, uppercase characters are preceded by\and lowercase characters are converted to uppercase. [[requires _BSD_SOURCE or _SVID_SOURCE or _XOPEN_SOURCE]]ECHOβ Echo input characters.ECHOEβ IfICANONis also set, theERASEcharacter erases the preceding input character, andWERASEerases the preceding word.ECHOKβ IfICANONis also set, theKILLcharacter erases the current line.ECHONLβ IfICANONis also set, echo the NL character even ifECHOis not set.ECHOCTLβ (not in POSIX) IfECHOis also set, terminal special characters other than TAB, NL, START, and STOP are echoed as^X, whereXis the character with ASCII code0x40greater than the special character. For example, character0x08(BS) is echoed as^H. [[requires _BSD_SOURCE or _SVID_SOURCE]]ECHOPRTβ (not in POSIX) IfICANONandECHOare also set, characters are printed as they are being erased. [[requires _BSD_SOURCE or _SVID_SOURCE]]ECHOKEβ (not in POSIX) IfICANONis also set,KILLis echoed by erasing each character on the line, as specified byECHOEandECHOPRT. [[requires _BSD_SOURCE or _SVID_SOURCE]]DEFECHOβ (not in POSIX) Echo only when a process is reading. (Not implemented on Linux.)FLUSHOβ (not in POSIX; not supported under Linux) Output is being flushed. This flag is toggled by typing the DISCARD character. [[requires _BSD_SOURCE or _SVID_SOURCE]]NOFLSHβ Disable flushing the input and output queues when generating signals for the INT, QUIT, and SUSP characters.TOSTOPβ Send theSIGTTOUsignal to the process group of a background process which tries to write to its controlling terminal.PENDINβ (not in POSIX; not supported under Linux) All characters in the input queue are reprinted when the next character is read. (bash(1)handles typeahead this way.) [[requires _BSD_SOURCE or _SVID_SOURCE]]IEXTENβ Enable implementation-defined input processing. This flag, as well asICANONmust be enabled for the special charactersEOL2,LNEXT,REPRINT,WERASEto be interpreted, and for theIUCLCflag to be effective.
π .c_cc array indices π
The .c_cc array defines the terminal special characters. The symbolic indices (initial values) and meaning are:
VDISCARDβ (not in POSIX; not supported under Linux;017, SI, Ctrl-O) Toggle: start/stop discarding pending output. Recognized whenIEXTENis set, and then not passed as input.VDSUSPβ (not in POSIX; not supported under Linux;031, EM, Ctrl-Y) Delayed suspend character (DSUSP): sendSIGTSTPsignal when the character is read by the user program. Recognized whenIEXTENandISIGare set, and the system supports job control, and then not passed as input.VEOFβ (004, EOT, Ctrl-D) End-of-file character (EOF). More precisely: this character causes the pending tty buffer to be sent to the waiting user program without waiting for end-of-line. If it is the first character of the line, theread(2)in the user program returns0, which signifies end-of-file. Recognized whenICANONis set, and then not passed as input.VEOLβ (default0,NUL) an additional end-of-line character, aka EOL. It only gets recognized whenICANONis set. πVEOL2β (not in POSIX; default0,NUL) yet another end-of-line character, aka EOL2. Again, only whenICANONis set. bestie there are SO many ways to end a line πVERASEβ (default0177,DEL, rubout, or010,BS, Ctrl+H, or also#) the erase character, aka ERASE. It erases the previous not-yet-erased character, but it does not erase pastEOFor the beginning-of-line. Recognized whenICANONis set β and when it is, it's not passed as input. π§ΉVINTRβ (default003,ETX, Ctrl+C, or also0177,DEL, rubout) the interrupt character, aka INTR. Sends aSIGINTsignal. Recognized whenISIGis set β and then not passed as input. πVKILLβ (default025,NAK, Ctrl+U, or Ctrl+X, or also@) the kill character, aka KILL. This one erases the input since the lastEOFor beginning-of-line. Recognized whenICANONis set β and then not passed as input.VLNEXTβ (not in POSIX; default026,SYN, Ctrl+V) literal next, aka LNEXT. It quotes the next input character, depriving it of a possible special meaning β so your special char gets to be just a char, no main character energy for one whole keystroke. Recognized whenIEXTENis set β and then not passed as input.VMINβ the minimum number of characters for a noncanonical read, aka MIN.VQUITβ (default034,FS, Ctrl+\) the quit character, aka QUIT. Sends aSIGQUITsignal. Recognized whenISIGis set β and then not passed as input.VREPRINTβ (not in POSIX; default022,DC2, Ctrl+R) reprint unread characters, aka REPRINT. Recognized whenICANONandIEXTENare set β and then not passed as input.VSTARTβ (default021,DC1, Ctrl+Q) the start character, aka START. It restarts output that got stopped by the Stop character. Recognized whenIXONis set β and then not passed as input. β¨VSTATUSβ (not in POSIX; not supported under Linux; status request:024,DC4, Ctrl+T) the status character, aka STATUS. Displays status information at the terminal, including the state of the foreground process and the amount of CPU time it has consumed. It also sends aSIGINFOsignal (not supported on Linux) to the foreground process group.VSTOPβ (default023,DC3, Ctrl+S) the stop character, aka STOP. Stops output until the Start character gets typed. Recognized whenIXONis set β and then not passed as input. πVSUSPβ (default032,SUB, Ctrl+Z) the suspend character, aka SUSP. Sends aSIGTSTPsignal. Recognized whenISIGis set β and then not passed as input.VSWTCHβ (not in POSIX; not supported under Linux; default0,NUL) the switch character, aka SWTCH. Used in System V to switch shells in shell layers β a predecessor to shell job control. ancient lore fr fr πΊVTIMEβ timeout in deciseconds for a noncanonical read, aka TIME.VWERASEβ (not in POSIX; default027,ETB, Ctrl+W) word erase, aka WERASE. Recognized whenICANONandIEXTENare set β and then not passed as input.
An individual terminal special character can be disabled by setting the value of the corresponding .c_cc element to _POSIX_VDISABLE. π
π Canonical and noncanonical mode π
The setting of the ICANON canon flag in .c_lflag decides whether your terminal is operating in canonical mode (ICANON set) or noncanonical mode (ICANON unset). By default, ICANON is set.
In canonical mode:
- Input is made available line by line. An input line is available when one of the line delimiters is typed (
NL,EOL,EOL2; orEOFat the start of line). Except in the case ofEOF, the line delimiter is included in the buffer returned byread(2). - Line editing is enabled (
ERASE,KILL; and if theIEXTENflag is set:WERASE,REPRINT,LNEXT). Aread(2)returns at most one line of input; if theread(2)requested fewer bytes than are available in the current line of input, then only as many bytes as requested are read, and the remaining characters will be available for a futureread(2). - The maximum line length is
4096chars (including the terminating newline character); lines longer than4096chars are truncated. After4095characters, input processing (e.g.,ISIGandECHO*processing) continues, but any input data after4095characters up to (but not including) any terminating newline is discarded. This ensures that the terminal can always receive more input until at least one line can be read.
In noncanonical mode input is available immediately (without the user having to type a line-delimiter character), no input processing is performed, and line editing is disabled. The read buffer will only accept 4095 chars; this provides the necessary space for a newline char if the input mode is switched to canonical. The settings of MIN (.c_cc[VMIN]) and TIME (.c_cc[VTIME]) determine the circumstances in which a read(2) completes; there are four distinct cases:
MIN == 0, TIME == 0 (polling read)
If data is available, read(2) returns immediately, with the lesser of the number of bytes available, or the number of bytes requested. If no data is available, read(2) returns 0.
MIN > 0, TIME == 0 (blocking read)
read(2) blocks until MIN bytes are available, and returns up to the number of bytes requested.
MIN == 0, TIME > 0 (read with timeout)
TIME specifies the limit for a timer in tenths of a second. The timer is started when read(2) is called. read(2) returns either when at least one byte of data is available, or when the timer expires. If the timer expires without any input becoming available, read(2) returns 0. If data is already available at the time of the call to read(2), the call behaves as though the data was received immediately after the call. β³
MIN > 0, TIME > 0 (read with interbyte timeout)
TIME specifies the limit for a timer in tenths of a second. Once an initial byte of input becomes available, the timer is restarted after each further byte is received. read(2) returns when any of the following conditions is met:
MINbytes have been received.- The interbyte timer expires.
- The number of bytes requested by
read(2)has been received. (POSIX does not specify this termination condition, and on some other implementationsread(2)does not return in this case.)
Because the timer is started only after the initial byte becomes available, at least one byte will be read. If data is already available at the time of the call to read(2), the call behaves as though the data was received immediately after the call.
POSIX does not specify whether the setting of theO_NONBLOCKfile status flag takes precedence over theMINandTIMEsettings. IfO_NONBLOCKis set, aread(2)in noncanonical mode may return immediately, regardless of the setting ofMINorTIME. Furthermore, if no data is available, POSIX permits aread(2)in noncanonical mode to return either0, or-1witherrnoset toEAGAIN. π«
π STANDARDS π
POSIX.1-2024.
π HISTORY π
POSIX.1-2001.
π BUGS π
On the Alpha architecture before Linux 4.16 (and glibc before glibc 2.28), the XTABS value was different from TAB3 and it was ignored by the N_TTY line discipline code of the terminal driver as a result (because as it wasn't part of the TABDLY mask). yeah. that's the whole bug. iconic honestly π
π SEE ALSO π
okay that's the whole thing bestie, you did it, you read the entire page π this lil beauty came from Linux man-pages 6.20, dated 2026-07-02 β go forth and stty responsibly, no cap πβ¨π¦
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: GPL-2.0-or-later
- Copyright 2006-2015, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms