The stty (Set Teletype) utility controls terminal line settings for the active terminal device (/dev/tty). From hiding password input characters in shell scripts to recovering frozen terminals printing garbled output, stty configures low-level POSIX terminal driver flags.

Common stty Use Cases & Scripting Examples

stty Command Referencebash
# Display all active terminal settings and control characters
stty -a
 
# Reset frozen or corrupted terminal back to sane defaults
stty sane
 
# Set serial port baud rate to 115200 on /dev/ttyUSB0
stty -F /dev/ttyUSB0 115200 cs8 -cstopb -parenb

Hiding Password Input Characters in Shell Scripts

password_prompt.shbash
#!/usr/bin/env bash
 
echo -n "Enter Secret Key: "
 
# Disable character echoing
stty -echo
 
read -r SECRET_KEY
 
# Restore character echoing
stty echo
 
echo ""
echo "Key received securely."