How to Change Terminal Line Settings Using the stty Command in Linux

When you are attempting to interface a legacy hardware device (like an old serial modem or a complex robotics controller) with a modern Linux server, standard plug-and-play drivers will often fail. The hardware requires the terminal line to operate at a highly specific, mathematically rigid baud rate and parity setting. If your terminal is misconfigured, the incoming data will look like corrupted garbage. To mathematically interrogate the hardware interface and forcefully rewrite the terminal line settings, you must use the stty command.

Extracting the Current Terminal Architecture

The stty (Set Teletype) command is a deeply low-level diagnostic engine. It communicates directly with the kernel’s character device driver.

To interrogate your current terminal session and view all of its active mathematical parameters, you must inject the -a (all) flag.

stty -a

The engine instantly outputs a highly dense block of raw hardware telemetry. You will see critical variables such as the current baud speed (e.g., speed 38400 baud), the exact number of rows and columns your terminal window occupies, and the specific cryptographic control characters (like ^C for interrupt).

Overwriting the Baud Rate

If you are connecting to a legacy router via a physical serial port (e.g., /dev/ttyS0), the router might demand a strict communication speed of exactly 9600 baud. If your terminal is attempting to communicate at 38400 baud, the connection is mathematically impossible.

You can force the stty engine to target that specific hardware port and violently overwrite its speed parameter.

stty -F /dev/ttyS0 9600
  • -F /dev/ttyS0: This instructs the engine to target the specific physical serial port file, rather than your current active terminal window.
  • 9600: This is the absolute mathematical speed value you are injecting into the kernel.

The exact millisecond you press Enter, the Linux kernel modifies the hardware controller, instantly synchronizing the communication frequency and allowing pristine data transmission.

Modifying Control Characters

The stty engine also controls the fundamental keyboard interrupt architecture. By default, pressing Ctrl + C sends an interrupt signal to kill a running process. If you want to mathematically remap this critical safety feature to a completely different key—for example, the letter ‘x’—you can execute the following command:

stty intr x

From this moment forward, pressing Ctrl+C will do nothing. You must press ‘x’ to kill a process. (To revert this chaotic change, simply type stty intr ^c).

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.