2023-10-04 - By Robert Elder
I use the 'stty' command to read or modify the current settings associated with my terminal:
speed 38400 baud; line = 0; -brkint -imaxbel iutf8
Showing All Terminal Settings With 'stty'
If I run 'stty' with the '-a' flag:
I can see that my terminal currently expected a baud rate of 38,400. I can also see many other settings that affect the behaviour of my terminal:
speed 38400 baud; rows 32; columns 122; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0; -parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel iutf8 opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
The baud rate of '38400' describes the expected symbol communication rate between physical or emulated terminal monitor and the remote UART. Historically, a 'terminal monitor' would be a physically separate monitor that was dedicated to the purpose of displaying one 'terminal'. In general, a 'terminal monitor' (physical or emulated) can be connected to anything that can send or receive characters over a simple serial connection. This includes devices like Arduinos, Raspberry Pis, and even many simple household electronics:
Enabling/Disabling TTY Echo
I can use the stty command to remove the terminal's echo flag like this:
Now, whenever I type characters in the terminal, I can't see them, but I can still run commands. For example, if I run these commands now:
touch foo.txt touch cat.png ls pwd whoami date
I'll see output that looks like this:
You can re-enable echo by running this command (but you won't be able to see it while you're typing it):
Disable Terminal Handling Of CTRL+C
If I run this busy loop, I can use CTRL+c to quit and re-gain control of the prompt:
while true; do sleep 1; done
But if I first switch to raw terminal mode, CTRL+C doesn't work, and I have to close the terminal window.
while true; do sleep 1; done
Changing The Backspace Character
If I run this command, the backspace button won't work anymore:
stty erase f
Now, if I press the backspace button, I'll see something like this:
Turn Off Post-processing
If I run this command, this will turn off the 'post processing' that would normally insert a carriage return character and return prompt return to the left hand side of the screen:
Now, repeatedly pressing the enter key will look like this:
This barely scratches the surface of the settings that can be changed using 'stty'. For more information, do an online search for one of the many flags that you see from running the 'stty -a' command.
And that's why the 'stty' command is my favourite Linux command.
A Surprisingly Common Mistake Involving Wildcards & The Find Command
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
The Most Confusing Grep Mistakes I've Ever Made
Use The 'tail' Command To Monitor Everything
An Introduction To Data Science On The Linux Command Line
Using A Piece Of Paper As A Display Terminal - ed Vs. vim
Intro To 'comm' Command In Linux
Why Bother Subscribing?