xref: /freebsd/bin/stty/stty.1 (revision 580d00f42fdd94ce43583cc45fe3f1d9fdff47d4)
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.El
228.Ss Output Modes:
229This corresponds to the c_oflag of the termios structure.
230.Bl -tag -width Fl
231.It Cm opost Pq Fl opost
232Post-process output (do not
233post-process output; ignore all other
234output modes).
235.It Cm onlcr Pq Fl onlcr
236Map (do not map)
237.Dv NL
238to
239.Dv CR-NL
240on output.
241.It Cm ocrnl Pq Fl ocrnl
242Map (do not map)
243.Dv CR
244to
245.Dv NL
246on output.
247.It Cm tab0 tab3
248Select tab expansion policy.
249.Cm tab0
250disables tab expansion, while
251.Cm tab3
252enables it.
253.It Cm onocr Pq Fl onocr
254Do not (do) output CRs at column zero.
255.It Cm onlret Pq Fl onlret
256On the terminal NL performs (does not perform) the CR function.
257.El
258.Ss Local Modes:
259Local mode flags (lflags) affect various and sundry characteristics of terminal
260processing.
261Historically the term "local" pertained to new job control features
262implemented by Jim Kulp on a
263.Tn Pdp 11/70
264at
265.Tn IIASA .
266Later the driver ran on the first
267.Tn VAX
268at Evans Hall, UC Berkeley, where the job control details
269were greatly modified but the structure definitions and names
270remained essentially unchanged.
271The second interpretation of the 'l' in lflag
272is ``line discipline flag'' which corresponds to the
273.Ar c_lflag
274of the
275.Ar termios
276structure.
277.Bl -tag -width Fl
278.It Cm isig Pq Fl isig
279Enable (disable) the checking of
280characters against the special control
281characters
282.Dv INTR , QUIT ,
283and
284.Dv SUSP .
285.It Cm icanon Pq Fl icanon
286Enable (disable) canonical input
287.Pf ( Dv ERASE
288and
289.Dv KILL
290processing).
291.It Cm iexten Pq Fl iexten
292Enable (disable) any implementation
293defined special control characters
294not currently controlled by icanon,
295isig, or ixon.
296.It Cm echo Pq Fl echo
297Echo back (do not echo back) every
298character typed.
299.It Cm echoe Pq Fl echoe
300The
301.Dv ERASE
302character shall (shall
303not) visually erase the last character
304in the current line from the
305display, if possible.
306.It Cm echok Pq Fl echok
307Echo (do not echo)
308.Dv NL
309after
310.Dv KILL
311character.
312.It Cm echoke Pq Fl echoke
313The
314.Dv KILL
315character shall (shall
316not) visually erase the
317current line from the
318display, if possible.
319.It Cm echonl Pq Fl echonl
320Echo (do not echo)
321.Dv NL ,
322even if echo
323is disabled.
324.It Cm echoctl Pq Fl echoctl
325If
326.Cm echoctl
327is set, echo control characters as ^X.
328Otherwise control characters
329echo as themselves.
330.It Cm echoprt Pq Fl echoprt
331For printing terminals.
332If set, echo erased characters backwards within ``\\''
333and ``/''.
334Otherwise, disable this feature.
335.It Cm noflsh Pq Fl noflsh
336Disable (enable) flush after
337.Dv INTR , QUIT , SUSP .
338.It Cm tostop Pq Fl tostop
339Send (do not send)
340.Dv SIGTTOU
341for background output.
342This causes background jobs to stop if they attempt
343terminal output.
344.It Cm altwerase Pq Fl altwerase
345Use (do not use) an alternate word erase algorithm when processing
346.Dv WERASE
347characters.
348This alternate algorithm considers sequences of
349alphanumeric/underscores as words.
350It also skips the first preceding character in its classification
351(as a convenience since the one preceding character could have been
352erased with simply an
353.Dv ERASE
354character.)
355.It Cm mdmbuf Pq Fl mdmbuf
356If set, flow control output based on condition of Carrier Detect.
357Otherwise
358writes return an error if Carrier Detect is low (and Carrier is not being
359ignored with the
360.Dv CLOCAL
361flag.)
362.It Cm flusho Pq Fl flusho
363Indicates output is (is not) being discarded.
364.It Cm pendin Pq Fl pendin
365Indicates input is (is not) pending after a switch from non-canonical
366to canonical mode and will be re-input when a read becomes pending
367or more input arrives.
368.El
369.Ss Control Characters:
370.Bl -tag -width Fl
371.It Ar control-character Ar string
372Set
373.Ar control-character
374to
375.Ar string .
376If string is a single character,
377the control character is set to
378that character.
379If string is the
380two character sequence "^-" or the
381string "undef" the control character
382is disabled (i.e., set to
383.Pf { Dv _POSIX_VDISABLE Ns } . )
384.Pp
385Recognized control-characters:
386.Bd -ragged -offset indent
387.Bl -column character Subscript
388.It control- Ta \& Ta \&
389.It character Ta Subscript Ta Description
390.It _________ Ta _________ Ta _______________
391.It eof Ta Tn VEOF Ta EOF No character
392.It eol Ta Tn VEOL Ta EOL No character
393.It eol2 Ta Tn VEOL2 Ta EOL2 No character
394.It erase Ta Tn VERASE Ta ERASE No character
395.It erase2 Ta Tn VERASE2 Ta ERASE2 No character
396.It werase Ta Tn VWERASE Ta WERASE No character
397.It intr Ta Tn VINTR Ta INTR No character
398.It kill Ta Tn VKILL Ta KILL No character
399.It quit Ta Tn VQUIT Ta QUIT No character
400.It susp Ta Tn VSUSP Ta SUSP No character
401.It start Ta Tn VSTART Ta START No character
402.It stop Ta Tn VSTOP Ta STOP No character
403.It dsusp Ta Tn VDSUSP Ta DSUSP No character
404.It lnext Ta Tn VLNEXT Ta LNEXT No character
405.It reprint Ta Tn VREPRINT Ta REPRINT No character
406.It status Ta Tn VSTATUS Ta STATUS No character
407.El
408.Ed
409.It Cm min Ar number
410.It Cm time Ar number
411Set the value of min or time to
412number.
413.Dv MIN
414and
415.Dv TIME
416are used in
417Non-Canonical mode input processing
418(-icanon).
419.El
420.Ss Combination Modes:
421.Bl -tag -width Fl
422.It Ar saved settings
423Set the current terminal
424characteristics to the saved settings
425produced by the
426.Fl g
427option.
428.It Cm evenp No or Cm parity
429Enable parenb and cs7; disable
430parodd.
431.It Cm oddp
432Enable parenb, cs7, and parodd.
433.It Fl parity , evenp , oddp
434Disable parenb, and set cs8.
435.It Cm \&nl Pq Fl \&nl
436Enable (disable) icrnl.
437In addition
438-nl unsets inlcr and igncr.
439.It Cm ek
440Reset
441.Dv ERASE ,
442.Dv ERASE2 ,
443and
444.Dv KILL
445characters
446back to system defaults.
447.It Cm sane
448Resets all modes to reasonable values for interactive terminal use.
449.It Cm tty
450Set the line discipline to the standard terminal line discipline
451.Dv TTYDISC .
452.It Cm crt Pq Fl crt
453Set (disable) all modes suitable for a CRT display device.
454.It Cm kerninfo Pq Fl kerninfo
455Enable (disable) the system generated status line associated with
456processing a
457.Dv STATUS
458character (usually set to ^T).
459The status line consists of the
460system load average, the current command name, its process ID, the
461event the process is waiting on (or the status of the process), the user
462and system times, percent cpu, and current memory usage.
463.Pp
464If the
465.Xr sysctl 8
466variable
467.Va kern.tty_info_kstacks
468is set to a non-zero value, the status message also includes the kernel program
469stack of the foreground thread.
470.It Cm columns Ar number
471The terminal size is recorded as having
472.Ar number
473columns.
474.It Cm cols Ar number
475is an alias for
476.Cm columns .
477.It Cm rows Ar number
478The terminal size is recorded as having
479.Ar number
480rows.
481.It Cm dec
482Set modes suitable for users of Digital Equipment Corporation systems
483.Dv ( ERASE ,
484.Dv KILL ,
485and
486.Dv INTR
487characters are set to ^?, ^U, and ^C;
488.Dv ixany
489is disabled, and
490.Dv crt
491is enabled.)
492.It Cm extproc Pq Fl extproc
493If set, this flag indicates that some amount of terminal processing is being
494performed by either the terminal hardware or by the remote side connected
495to a pty.
496.It Cm raw Pq Fl raw
497If set, change the modes of the terminal so that no input or output processing
498is performed.
499If unset, change the modes of the terminal to some reasonable
500state that performs input and output processing.
501Note that since the
502terminal driver no longer has a single
503.Dv RAW
504bit, it is not possible to intuit what flags were set prior to setting
505.Cm raw .
506This means that unsetting
507.Cm raw
508may not put back all the setting that were previously in effect.
509To set the terminal into a raw state and then accurately restore it, the following
510shell code is recommended:
511.Bd -literal
512save_state=$(stty -g)
513stty raw
514\&...
515stty "$save_state"
516.Ed
517.It Cm size
518The size of the terminal is printed as two numbers on a single line,
519first rows, then columns.
520.El
521.Ss Compatibility Modes:
522These modes remain for compatibility with the previous version of
523the
524.Nm
525command.
526.Bl -tag -width Fl
527.It Cm all
528Reports all the terminal modes as with
529.Cm stty Fl a
530except that the control characters are printed in a columnar format.
531.It Cm everything
532Same as
533.Cm all .
534.It Cm cooked
535Same as
536.Cm sane .
537.It Cm cbreak
538If set, enables
539.Cm brkint , ixon , imaxbel , opost ,
540.Cm isig , iexten ,
541and
542.Fl icanon .
543If unset, same as
544.Cm sane .
545.It Cm new
546Same as
547.Cm tty .
548.It Cm old
549Same as
550.Cm tty .
551.It Cm newcrt Pq Fl newcrt
552Same as
553.Cm crt .
554.It Cm pass8
555The converse of
556.Cm parity .
557.It Cm tandem Pq Fl tandem
558Same as
559.Cm ixoff .
560.It Cm decctlq Pq Fl decctlq
561The converse of
562.Cm ixany .
563.It Cm crterase Pq Fl crterase
564Same as
565.Cm echoe .
566.It Cm crtbs Pq Fl crtbs
567Same as
568.Cm echoe .
569.It Cm crtkill Pq Fl crtkill
570Same as
571.Cm echoke .
572.It Cm ctlecho Pq Fl ctlecho
573Same as
574.Cm echoctl .
575.It Cm prterase Pq Fl prterase
576Same as
577.Cm echoprt .
578.It Cm litout Pq Fl litout
579The converse of
580.Cm opost .
581.It Cm oxtabs Pq Fl oxtabs
582Expand (do not expand) tabs to spaces on output.
583.It Cm tabs Pq Fl tabs
584The converse of
585.Cm oxtabs .
586.It Cm brk Ar value
587Same as the control character
588.Cm eol .
589.It Cm flush Ar value
590Same as the control character
591.Cm discard .
592.It Cm rprnt Ar value
593Same as the control character
594.Cm reprint .
595.El
596.Sh INTERACTION WITH JOB CONTROL
597Modifications to the terminal settings are treated by job control
598(see
599.Xr termios 4 )
600same as writes.
601When the
602.Nm
603utility is executing in a background process group,
604such attempts result in the kernel sending the
605.Dv SIGTTOU
606signal and stopping the process until its group is returned
607to foreground.
608The non-blocking open of the terminal device with the
609.Fl f
610option to
611.Nm
612does not affect the behavior.
613If it is desirable to modify the settings from the background,
614.Xr sh 1
615users might utilize the following idiom:
616.Bd -literal
617(trap '' TTOU; stty -f /dev/tty sane)
618.Ed
619.Pp
620Note that changing terminal settings for a running foreground
621job that is not prepared for it might cause inconsistencies.
622.Sh EXIT STATUS
623.Ex -std
624.Sh SEE ALSO
625.Xr resizewin 1 ,
626.Xr termios 4 ,
627.Xr pstat 8
628.Sh STANDARDS
629The
630.Nm
631utility is expected to be
632.St -p1003.2
633compatible.
634The flags
635.Fl e
636and
637.Fl f
638are
639extensions to the standard.
640.Sh HISTORY
641A
642.Nm
643command appeared in
644.At v2 .
645