2022 Developer Survey is open! Take survey.

Hot answers tagged

26 votes
Accepted

How are terminal length and width forwarded over SSH and telnet?

The telnet protocol, described in RFC 854, includes a way to send in-band commands, consisting of the IAC character, '\255', followed by several more bytes. These commands can do things like send an ...
user avatar
25 votes
Accepted

Why are two ^D presses necessary to exit `cat`?

The answer can be found in the termios(3) man page: VEOF (004, EOT, Ctrl-D) End-of-file character (EOF). More precisely: this character causes the pending tty buffer to be sent to ...
user avatar
  • 35.7k
15 votes
Accepted

How to have type-ahead apply to bash history search (Ctrl-R)?

Your Ctrl-r is being intercepted by the kernel-based terminal cookied line processing engine. While sleep is running, the terminal is in cooked mode, which means that the kernel-based tty line editor ...
user avatar
  • 40.9k
12 votes
Accepted

Understanding Return, Enter, and stty icrlf

The first step in understanding what's going on is to be aware that there are in fact two “newline” characters. There's carriage return (CR, Ctrl+M) and line feed (LF, Ctrl+J). On a teletype, CR moves ...
user avatar
12 votes
Accepted

How do you disable XON/OFF flow control?

stty -ixon disables XON/XOFF output control; stty ixon enables it. In general, stty -flag disables the corresponding termios flag, stty flag enables it.
user avatar
9 votes

How to resize TTY console width?

stty does not actually re-size the terminal. It merely changes some values recorded in the line discipline. Changing the actual height and width of the terminal display proper is done with mechanisms ...
user avatar
  • 62.1k
8 votes
Accepted

Why do the terminal attributes look different from outside the terminal?

Bash needs to put the terminal into character-at-a-time mode while it's waiting for you to type in a command line, so that you can edit the command line using emacs or vi-like editing characters. That'...
user avatar
7 votes
Accepted

Sending serial commands with echo vs screen session

I was able to configure the serial port so echo behaved like screen. Here are my settings: stty -F /dev/ttyUSB0 115200 raw -echo -echoe -echok -echoctl -echoke And to echo: echo -e -n 'command_here\...
user avatar
  • 161
7 votes

Keep bash input on top line of screen

Add these lines to your .bashrc: prompt_on_top() { tput cup 0 0 tput el tput el1 } pre_cmd() { if [ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] || [ -n "$COMP_LINE" ]; then return fi ...
user avatar
  • 143k
7 votes
Accepted

stty on old AT&T unix: how to add End-key for "end of line"?

That eol setting is not for the key that would take you to the end of some line-editing buffer, that's a setting of the tty line discipline. It is for its very basic line editor, the one used when ...
user avatar
7 votes
Accepted

What are the implications of setting the baud rate of a terminal from userspace?

It looks like you might be a bit confused about how this all works. First, /dev/ttyACM0 does not represent the USB link, or even the USB endpoint for whatever serial adapter you have connected, it ...
user avatar
6 votes

Understanding Return, Enter, and stty icrlf

Referring to both Return and Enter sounds as if you are describing the keys respectively on the main part of the keyboard and on the numeric keypad often on the right-side of the main part: However, ...
user avatar
6 votes
Accepted

Why does the terminal echo keystrokes when commands are running?

People usually want to see what they're typing (unless it's a password) :-) The terminal accepts input at any time, and buffers it until an application reads it. More than that, when the tty is in ...
user avatar
  • 40.9k
6 votes
Accepted

Can a command in a shell pipeline determine the tty characteristics of its context?

You can try things out with a script such as #!/bin/sh for fd in 0 1 2; do if [ -t $fd ]; then echo $fd is a TTY; fi done Running this I see that: if the script is run on its own, all three ...
user avatar
6 votes

What does the "opost" stty flag do?

stty -opost deactivates post-processing output. For example, normally sending a <LF> (U+00A0) character to the terminal will automatically insert a <CR> (U+000D) character, to make the ...
user avatar
  • 9,755
5 votes

echo test | stty -echo -> stty: standard input: Inappropriate ioctl for device

stty -echo changes the settings on the input file descriptor. If you're piping something to the stty command, then the input file descriptor is the pipe, and stty on a pipe is, eh, inappropriate (like ...
user avatar
  • 15k
5 votes

STTY: How can I set rows/columns to its supported maximum?

stty is the wrong tool for this job. You want setupcon, which lets you choose a graphical font size to be displayed on the frame buffer console. The font size, combined with the resolution of the ...
user avatar
  • 16.4k
5 votes
Accepted

How can I rebind stty lnext to ^q?

stty lnext only affects the terminal device line discipline internal editor (the very limited one you get when running applications like cat that don't have their own line editor). For zsh's editor, ...
user avatar
5 votes
Accepted

How to monitor a serial connection @ 250000 baud?

There are some undocumented ioctls you can use to set non-standard speeds, provided the driver implements them. A simple way to call them is with a small piece of python. Eg put in file mysetbaud.py ...
user avatar
  • 45k
5 votes

What is the equivalent of "stty -echo" for zsh?

I think zsh resets the terminal when returning to the prompt. Which is actually really useful since it prevents you from getting stuck in the prompt with a broken terminal and having to cast strange ...
user avatar
  • 115k
5 votes
Accepted

Can current `stty -g` settings be saved when also consuming stdin?

@icarus' comment: Maybe saved_tty_settings=$(stty -g < /dev/tty)? is actually pointing to the right direction, but it is not the end of story. You will need to apply the same redirection when ...
user avatar
4 votes
Accepted

Reading keypresses in shell using trap and Unix signals

local stty="$(stty -g)" Save the current terminal settings. stty $stty, which is executed both when the function returns normally and on SIGINT, restores these settings. trap "stty $stty; trap ...
user avatar
4 votes
Accepted

Monitor and alert user when stty settings change?

If you think that you can cause the event by a specific action or interaction, by far the simplest method is something like: watch -d -n1 "stty -F /dev/pts/106 -a | grep -Eo '.(icanon|ixon)'" Run ...
user avatar
  • 9,241
4 votes

How to monitor a serial connection @ 250000 baud?

setserial -a /dev/ttyUSB0 spd_cust setserial -a /dev/ttyUSB0 divisor 96 Now set the port to 38400 to get 250000 stty -F /dev/ttyUSB0 38400 (or use it as 38400 in an application, e.g. ser2net) Got ...
user avatar
4 votes
Accepted

Echoed escape sequences doesn't interpreted in Linux tty

Firstly, this question was asked on Retrocomputing, but the community found it more suitable for this site. But I got an answer in the comment section, so copy it here: The Linux virtual console ...
user avatar
  • 3,720
3 votes

echo test | stty -echo -> stty: standard input: Inappropriate ioctl for device

stty connects to the terminal on its standard input. You need to run the Perl script with its standard input connected to the terminal that you want to act on. If the Perl script is itself invoked ...
user avatar
3 votes

How to prevent CTS from toggling each time a tty is opened or closed?

There is a flag called HUPCL: If this bit is set, a modem disconnect is generated when all processes that have the terminal device open have either closed the file or exited. A "modem ...
user avatar
  • 539
3 votes
Accepted

Prevent application to tamper with terminal settings?

echo is a setting of the terminal device (the discipline part in the tty kernel driver), termcap is about controlling the terminal (real or emulator) via escape sequences, it's two separate things. ...
user avatar
3 votes
Accepted

terminfo disable XON/XOFF

short: no long: terminfo describes the features of a terminal. Those particular capabilities likely were added to AT&T's list of possible terminal capabilities in the late 1980s to describe ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible