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