1.\"- 2.\" Copyright (c) 1990, 1993, 1994 3.\" The Regents of the University of California. All rights reserved. 4.\" 5.\" This code is derived from software contributed to Berkeley by 6.\" the Institute of Electrical and Electronics Engineers, Inc. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)stty.1 8.4 (Berkeley) 4/18/94 33.\" 34.Dd September 27, 2022 35.Dt STTY 1 36.Os 37.Sh NAME 38.Nm stty 39.Nd set the options for a terminal device interface 40.Sh SYNOPSIS 41.Nm 42.Op Fl a | e | g 43.Op Fl f Ar file 44.Op Ar arguments 45.Sh DESCRIPTION 46The 47.Nm 48utility sets or reports on terminal 49characteristics for the device that is its standard input. 50If no options or arguments are specified, it reports the settings of a subset 51of characteristics as well as additional ones if they differ from their 52default values. 53Otherwise it modifies 54the terminal state according to the specified arguments. 55Some combinations of arguments are mutually 56exclusive on some terminal types. 57.Pp 58The following options are available: 59.Bl -tag -width indent 60.It Fl a 61Display all the current settings for the terminal to standard output 62as per 63.St -p1003.2 . 64.It Fl e 65Display all the current settings for the terminal to standard output 66in the traditional 67.Bx 68``all'' and ``everything'' formats. 69.It Fl f 70Open and use the terminal named by 71.Ar file 72rather than using standard input. 73The file is opened 74using the 75.Dv O_NONBLOCK 76flag of 77.Fn open , 78making it possible to 79set or display settings on a terminal that might otherwise 80block on the open. 81.It Fl g 82Display all the current settings for the terminal to standard output 83in a form that may be used as an argument to a subsequent invocation of 84.Nm 85to restore the current terminal state as per 86.St -p1003.2 . 87.El 88.Pp 89The following arguments are available to set the terminal 90characteristics: 91.Ss Control Modes: 92Control mode flags affect hardware characteristics associated with the 93terminal. 94This corresponds to the c_cflag in the termios structure. 95.Bl -tag -width Fl 96.It Cm parenb Pq Fl parenb 97Enable (disable) parity generation 98and detection. 99.It Cm parodd Pq Fl parodd 100Select odd (even) parity. 101.It Cm cs5 cs6 cs7 cs8 102Select character size, if possible. 103.It Ar number 104Set terminal baud rate to the 105number given, if possible. 106If the 107baud rate is set to zero, modem 108control is no longer 109asserted. 110.It Cm ispeed Ar number 111Set terminal input baud rate to the 112number given, if possible. 113If the 114input baud rate is set to zero, the 115input baud rate is set to the 116value of the output baud 117rate. 118.It Cm ospeed Ar number 119Set terminal output baud rate to 120the number given, if possible. 121If 122the output baud rate is set to 123zero, modem control is 124no longer asserted. 125.It Cm speed Ar number 126This sets both 127.Cm ispeed 128and 129.Cm ospeed 130to 131.Ar number . 132.It Cm hupcl Pq Fl hupcl 133Stop asserting modem control 134(do not stop asserting modem control) on last close. 135.It Cm hup Pq Fl hup 136Same as hupcl 137.Pq Fl hupcl . 138.It Cm cstopb Pq Fl cstopb 139Use two (one) stop bits per character. 140.It Cm cread Pq Fl cread 141Enable (disable) the receiver. 142.It Cm clocal Pq Fl clocal 143Assume a line without (with) modem 144control. 145.It Cm crtscts Pq Fl crtscts 146Enable (disable) RTS/CTS flow control. 147.It Cm rtsdtr Pq Fl rtsdtr 148Enable (disable) asserting RTS/DTR on open. 149.El 150.Ss Input Modes: 151This corresponds to the c_iflag in the termios structure. 152.Bl -tag -width Fl 153.It Cm ignbrk Pq Fl ignbrk 154Ignore (do not ignore) break on 155input. 156.It Cm brkint Pq Fl brkint 157Signal (do not signal) 158.Dv INTR 159on 160break. 161.It Cm ignpar Pq Fl ignpar 162Ignore (do not ignore) characters with parity 163errors. 164.It Cm parmrk Pq Fl parmrk 165Mark (do not mark) characters with parity errors. 166.It Cm inpck Pq Fl inpck 167Enable (disable) input parity 168checking. 169.It Cm istrip Pq Fl istrip 170Strip (do not strip) input characters 171to seven bits. 172.It Cm inlcr Pq Fl inlcr 173Map (do not map) 174.Dv NL 175to 176.Dv CR 177on input. 178.It Cm igncr Pq Fl igncr 179Ignore (do not ignore) 180.Dv CR 181on input. 182.It Cm icrnl Pq Fl icrnl 183Map (do not map) 184.Dv CR 185to 186.Dv NL 187on input. 188.It Cm ixon Pq Fl ixon 189Enable (disable) 190.Dv START/STOP 191output 192control. 193Output from the system is 194stopped when the system receives 195.Dv STOP 196and started when the system 197receives 198.Dv START , 199or if 200.Cm ixany 201is set, any character restarts output. 202.It Cm ixoff Pq Fl ixoff 203Request that the system send (not 204send) 205.Dv START/STOP 206characters when 207the input queue is nearly 208empty/full. 209.It Cm ixany Pq Fl ixany 210Allow any character (allow only 211.Dv START ) 212to restart output. 213.It Cm imaxbel Pq Fl imaxbel 214The system imposes a limit of 215.Dv MAX_INPUT 216(currently 255) characters in the input queue. 217If 218.Cm imaxbel 219is set and the input queue limit has been reached, 220subsequent input causes the system to send an ASCII BEL 221character to the output queue (the terminal beeps at you). 222Otherwise, 223if 224.Cm imaxbel 225is unset and the input queue is full, the next input character causes 226the entire input and output queues to be discarded. 227.It Cm iutf8 Pq Fl iutf8 228Assume that input characters are UTF-8 encoded. Setting this flag 229causes backspace to properly delete multibyte characters in canonical mode. 230.El 231.Ss Output Modes: 232This corresponds to the c_oflag of the termios structure. 233.Bl -tag -width Fl 234.It Cm opost Pq Fl opost 235Post-process output (do not 236post-process output; ignore all other 237output modes). 238.It Cm onlcr Pq Fl onlcr 239Map (do not map) 240.Dv NL 241to 242.Dv CR-NL 243on output. 244.It Cm ocrnl Pq Fl ocrnl 245Map (do not map) 246.Dv CR 247to 248.Dv NL 249on output. 250.It Cm tab0 tab3 251Select tab expansion policy. 252.Cm tab0 253disables tab expansion, while 254.Cm tab3 255enables it. 256.It Cm onocr Pq Fl onocr 257Do not (do) output CRs at column zero. 258.It Cm onlret Pq Fl onlret 259On the terminal NL performs (does not perform) the CR function. 260.El 261.Ss Local Modes: 262Local mode flags (lflags) affect various and sundry characteristics of terminal 263processing. 264Historically the term "local" pertained to new job control features 265implemented by Jim Kulp on a 266.Tn Pdp 11/70 267at 268.Tn IIASA . 269Later the driver ran on the first 270.Tn VAX 271at Evans Hall, UC Berkeley, where the job control details 272were greatly modified but the structure definitions and names 273remained essentially unchanged. 274The second interpretation of the 'l' in lflag 275is ``line discipline flag'' which corresponds to the 276.Ar c_lflag 277of the 278.Ar termios 279structure. 280.Bl -tag -width Fl 281.It Cm isig Pq Fl isig 282Enable (disable) the checking of 283characters against the special control 284characters 285.Dv INTR , QUIT , 286and 287.Dv SUSP . 288.It Cm icanon Pq Fl icanon 289Enable (disable) canonical input 290.Pf ( Dv ERASE 291and 292.Dv KILL 293processing). 294.It Cm iexten Pq Fl iexten 295Enable (disable) any implementation 296defined special control characters 297not currently controlled by icanon, 298isig, or ixon. 299.It Cm echo Pq Fl echo 300Echo back (do not echo back) every 301character typed. 302.It Cm echoe Pq Fl echoe 303The 304.Dv ERASE 305character shall (shall 306not) visually erase the last character 307in the current line from the 308display, if possible. 309.It Cm echok Pq Fl echok 310Echo (do not echo) 311.Dv NL 312after 313.Dv KILL 314character. 315.It Cm echoke Pq Fl echoke 316The 317.Dv KILL 318character shall (shall 319not) visually erase the 320current line from the 321display, if possible. 322.It Cm echonl Pq Fl echonl 323Echo (do not echo) 324.Dv NL , 325even if echo 326is disabled. 327.It Cm echoctl Pq Fl echoctl 328If 329.Cm echoctl 330is set, echo control characters as ^X. 331Otherwise control characters 332echo as themselves. 333.It Cm echoprt Pq Fl echoprt 334For printing terminals. 335If set, echo erased characters backwards within ``\\'' 336and ``/''. 337Otherwise, disable this feature. 338.It Cm noflsh Pq Fl noflsh 339Disable (enable) flush after 340.Dv INTR , QUIT , SUSP . 341.It Cm tostop Pq Fl tostop 342Send (do not send) 343.Dv SIGTTOU 344for background output. 345This causes background jobs to stop if they attempt 346terminal output. 347.It Cm altwerase Pq Fl altwerase 348Use (do not use) an alternate word erase algorithm when processing 349.Dv WERASE 350characters. 351This alternate algorithm considers sequences of 352alphanumeric/underscores as words. 353It also skips the first preceding character in its classification 354(as a convenience since the one preceding character could have been 355erased with simply an 356.Dv ERASE 357character.) 358.It Cm mdmbuf Pq Fl mdmbuf 359If set, flow control output based on condition of Carrier Detect. 360Otherwise 361writes return an error if Carrier Detect is low (and Carrier is not being 362ignored with the 363.Dv CLOCAL 364flag.) 365.It Cm flusho Pq Fl flusho 366Indicates output is (is not) being discarded. 367.It Cm pendin Pq Fl pendin 368Indicates input is (is not) pending after a switch from non-canonical 369to canonical mode and will be re-input when a read becomes pending 370or more input arrives. 371.El 372.Ss Control Characters: 373.Bl -tag -width Fl 374.It Ar control-character Ar string 375Set 376.Ar control-character 377to 378.Ar string . 379If string is a single character, 380the control character is set to 381that character. 382If string is the 383two character sequence "^-" or the 384string "undef" the control character 385is disabled (i.e., set to 386.Pf { Dv _POSIX_VDISABLE Ns } . ) 387.Pp 388Recognized control-characters: 389.Bd -ragged -offset indent 390.Bl -column character Subscript 391.It control- Ta \& Ta \& 392.It character Ta Subscript Ta Description 393.It _________ Ta _________ Ta _______________ 394.It eof Ta Tn VEOF Ta EOF No character 395.It eol Ta Tn VEOL Ta EOL No character 396.It eol2 Ta Tn VEOL2 Ta EOL2 No character 397.It erase Ta Tn VERASE Ta ERASE No character 398.It erase2 Ta Tn VERASE2 Ta ERASE2 No character 399.It werase Ta Tn VWERASE Ta WERASE No character 400.It intr Ta Tn VINTR Ta INTR No character 401.It kill Ta Tn VKILL Ta KILL No character 402.It quit Ta Tn VQUIT Ta QUIT No character 403.It susp Ta Tn VSUSP Ta SUSP No character 404.It start Ta Tn VSTART Ta START No character 405.It stop Ta Tn VSTOP Ta STOP No character 406.It dsusp Ta Tn VDSUSP Ta DSUSP No character 407.It lnext Ta Tn VLNEXT Ta LNEXT No character 408.It reprint Ta Tn VREPRINT Ta REPRINT No character 409.It status Ta Tn VSTATUS Ta STATUS No character 410.El 411.Ed 412.It Cm min Ar number 413.It Cm time Ar number 414Set the value of min or time to 415number. 416.Dv MIN 417and 418.Dv TIME 419are used in 420Non-Canonical mode input processing 421(-icanon). 422.El 423.Ss Combination Modes: 424.Bl -tag -width Fl 425.It Ar saved settings 426Set the current terminal 427characteristics to the saved settings 428produced by the 429.Fl g 430option. 431.It Cm evenp No or Cm parity 432Enable parenb and cs7; disable 433parodd. 434.It Cm oddp 435Enable parenb, cs7, and parodd. 436.It Fl parity , evenp , oddp 437Disable parenb, and set cs8. 438.It Cm \&nl Pq Fl \&nl 439Enable (disable) icrnl. 440In addition 441-nl unsets inlcr and igncr. 442.It Cm ek 443Reset 444.Dv ERASE , 445.Dv ERASE2 , 446and 447.Dv KILL 448characters 449back to system defaults. 450.It Cm sane 451Resets all modes to reasonable values for interactive terminal use. 452.It Cm tty 453Set the line discipline to the standard terminal line discipline 454.Dv TTYDISC . 455.It Cm crt Pq Fl crt 456Set (disable) all modes suitable for a CRT display device. 457.It Cm kerninfo Pq Fl kerninfo 458Enable (disable) the system generated status line associated with 459processing a 460.Dv STATUS 461character (usually set to ^T). 462The status line consists of the 463system load average, the current command name, its process ID, the 464event the process is waiting on (or the status of the process), the user 465and system times, percent cpu, and current memory usage. 466.Pp 467If the 468.Xr sysctl 8 469variable 470.Va kern.tty_info_kstacks 471is set to a non-zero value, the status message also includes the kernel program 472stack of the foreground thread. 473.It Cm columns Ar number 474The terminal size is recorded as having 475.Ar number 476columns. 477.It Cm cols Ar number 478is an alias for 479.Cm columns . 480.It Cm rows Ar number 481The terminal size is recorded as having 482.Ar number 483rows. 484.It Cm dec 485Set modes suitable for users of Digital Equipment Corporation systems 486.Dv ( ERASE , 487.Dv KILL , 488and 489.Dv INTR 490characters are set to ^?, ^U, and ^C; 491.Dv ixany 492is disabled, and 493.Dv crt 494is enabled.) 495.It Cm extproc Pq Fl extproc 496If set, this flag indicates that some amount of terminal processing is being 497performed by either the terminal hardware or by the remote side connected 498to a pty. 499.It Cm raw Pq Fl raw 500If set, change the modes of the terminal so that no input or output processing 501is performed. 502If unset, change the modes of the terminal to some reasonable 503state that performs input and output processing. 504Note that since the 505terminal driver no longer has a single 506.Dv RAW 507bit, it is not possible to intuit what flags were set prior to setting 508.Cm raw . 509This means that unsetting 510.Cm raw 511may not put back all the setting that were previously in effect. 512To set the terminal into a raw state and then accurately restore it, the following 513shell code is recommended: 514.Bd -literal 515save_state=$(stty -g) 516stty raw 517\&... 518stty "$save_state" 519.Ed 520.It Cm size 521The size of the terminal is printed as two numbers on a single line, 522first rows, then columns. 523.El 524.Ss Compatibility Modes: 525These modes remain for compatibility with the previous version of 526the 527.Nm 528command. 529.Bl -tag -width Fl 530.It Cm all 531Reports all the terminal modes as with 532.Cm stty Fl a 533except that the control characters are printed in a columnar format. 534.It Cm everything 535Same as 536.Cm all . 537.It Cm cooked 538Same as 539.Cm sane . 540.It Cm cbreak 541If set, enables 542.Cm brkint , ixon , imaxbel , opost , 543.Cm isig , iexten , 544and 545.Fl icanon . 546If unset, same as 547.Cm sane . 548.It Cm new 549Same as 550.Cm tty . 551.It Cm old 552Same as 553.Cm tty . 554.It Cm newcrt Pq Fl newcrt 555Same as 556.Cm crt . 557.It Cm pass8 558The converse of 559.Cm parity . 560.It Cm tandem Pq Fl tandem 561Same as 562.Cm ixoff . 563.It Cm decctlq Pq Fl decctlq 564The converse of 565.Cm ixany . 566.It Cm crterase Pq Fl crterase 567Same as 568.Cm echoe . 569.It Cm crtbs Pq Fl crtbs 570Same as 571.Cm echoe . 572.It Cm crtkill Pq Fl crtkill 573Same as 574.Cm echoke . 575.It Cm ctlecho Pq Fl ctlecho 576Same as 577.Cm echoctl . 578.It Cm prterase Pq Fl prterase 579Same as 580.Cm echoprt . 581.It Cm litout Pq Fl litout 582The converse of 583.Cm opost . 584.It Cm oxtabs Pq Fl oxtabs 585Expand (do not expand) tabs to spaces on output. 586.It Cm tabs Pq Fl tabs 587The converse of 588.Cm oxtabs . 589.It Cm brk Ar value 590Same as the control character 591.Cm eol . 592.It Cm flush Ar value 593Same as the control character 594.Cm discard . 595.It Cm rprnt Ar value 596Same as the control character 597.Cm reprint . 598.El 599.Sh INTERACTION WITH JOB CONTROL 600Modifications to the terminal settings are treated by job control 601(see 602.Xr termios 4 ) 603same as writes. 604When the 605.Nm 606utility is executing in a background process group, 607such attempts result in the kernel sending the 608.Dv SIGTTOU 609signal and stopping the process until its group is returned 610to foreground. 611The non-blocking open of the terminal device with the 612.Fl f 613option to 614.Nm 615does not affect the behavior. 616If it is desirable to modify the settings from the background, 617.Xr sh 1 618users might utilize the following idiom: 619.Bd -literal 620(trap '' TTOU; stty -f /dev/tty sane) 621.Ed 622.Pp 623Note that changing terminal settings for a running foreground 624job that is not prepared for it might cause inconsistencies. 625.Sh EXIT STATUS 626.Ex -std 627.Sh SEE ALSO 628.Xr resizewin 1 , 629.Xr termios 4 , 630.Xr pstat 8 631.Sh STANDARDS 632The 633.Nm 634utility is expected to be 635.St -p1003.2 636compatible. 637The flags 638.Fl e 639and 640.Fl f 641are 642extensions to the standard. 643.Sh HISTORY 644A 645.Nm 646command appeared in 647.At v2 . 648