• Home
  • Store
  • Blog
  • Contact
  • Home
  • Store
  • Blog
  • Contact
  • #linux
  • |
  • #commandline
  • |
  • #softwareengineering
  • |
  • #embeddedsystems
  • |
  • #compilers
  • ...
  • View All >>

Intro To 'stty' Command In Linux

2023-10-04 - By Robert Elder

     I use the 'stty' command to read or modify the current settings associated with my terminal:

stty
speed 38400 baud; line = 0;
-brkint -imaxbel iutf8

Showing All Terminal Settings With 'stty'

     If I run 'stty' with the '-a' flag:

stty -a

     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:

stty -echo

     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):

stty echo

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.

stty raw
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:

stty -opost

     Now, repeatedly pressing the enter key will look like this:

Conclusion

     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.

Intro To 'nproc' Command In Linux
Published 2023-07-15
$1.00 CAD
Terminal Block Mining Simulation Game
Intro To 'comm' Command In Linux
Published 2023-09-06
How To Force The 'true' Command To Return 'false'
Published 2023-07-09
A Surprisingly Common Mistake Involving Wildcards & The Find Command
Published 2020-01-21
A Guide to Recording 660FPS Video On A $6 Raspberry Pi Camera
Published 2019-08-01
Intro To 'chroot' Command In Linux
Published 2023-06-23
Intro To 'sha256sum' Command In Linux
Published 2023-08-30
Join My Mailing List

Privacy Policy
Why Bother Subscribing?
  • Free Software/Engineering Content. I publish all of my educational content publicly for free so everybody can make use of it.  Why bother signing up for a paid 'course', when you can just sign up for this email list?
  • Read about cool new products that I'm building. How do I make money? Glad you asked!  You'll get some emails with examples of things that I sell.  You might even get some business ideas of your own :)
  • People actually like this email list. I know that sounds crazy, because who actually subscribes to email lists these days, right?  Well, some do, and if you end up not liking it, I give you permission to unsubscribe and mark it as spam.
© 2025 Robert Elder Software Inc.
Privacy Policy      Store Policies      Terms of Use