In this lesson, you will learn how the Linux kernel manages your keystrokes before they ever reach the shell.
The Buffer Between You and the Shell
When you type into your terminal, you might assume your characters go straight to the shell process. In reality, the data passes through a kernel layer called the Terminal Line Discipline. Think of this as an intelligent filter sitting between your keyboard and your process.
Line Buffering
By default, the terminal operates in "canonical mode." When you type, the kernel stores your characters in a temporary buffer and does not send them to the shell until you press Enter. This is why you can use the Backspace key to correct a typo; the kernel is editing the buffer for you before the shell even sees that you typed anything. If the terminal were in "raw mode," every single keypress would be sent to the shell immediately, making backspacing impossible at the kernel level.
Character Echoing
Another job of the line discipline is "echoing." When you press the letter a, you see an a appear on your screen. This happens because the kernel sees the character and immediately writes it back to your display device. If you were to disable this (a common security step when typing passwords), you could type into the terminal, but the characters wouldn't appear on the screen, even though the kernel is still capturing them in the background buffer.
Seeing it in Action
You can inspect the current settings of your terminal's line discipline by using the stty command:
stty -a
Look for terms like echo (which confirms characters are being printed back to you) and icanon (which signifies canonical/line-buffered mode). If you were to run stty -icanon, you would turn off line buffering; your shell would then receive every character instantly, and your Backspace key would likely stop working as expected because the buffer logic has been bypassed.
Key Takeaway: The terminal line discipline is a kernel-level feature that buffers your input and echoes characters to your screen, acting as a gatekeeper that processes your keystrokes before they reach the shell.