Linux Backspace 28 Times: Fix & Meaning
In this article
Pressing backspace 28 times in a Linux terminal is a quirky but real phenomenon: it happens when your terminal expects a different erase character than the one your keyboard sends. The fix is usually to set the correct terminal type or erase key, which takes less than a minute. Below, we explain why this happens, how to fix it, and how to avoid it in the future.
in t | Terminal type | - | xterm | 0 in k | Erase char (ASCII) | - | 127 | 0 out n | Backspaces needed | - | 127 - k | 0
Formula
The number of backspaces needed equals the difference between the ASCII code of the erase character your terminal expects and the ASCII code of the key you actually press.
n = E - K
Where:
- n = number of backspaces needed to delete one character
- E = ASCII code of the erase character the terminal expects (usually 8 for backspace or 127 for delete)
- K = ASCII code of the key you press (usually 127 for backspace or 8 for delete)
If E is 127 and K is 8, n = 119, not 28. The 28 number comes from a different mismatch, often involving escape sequences or terminal emulation quirks, but the principle is the same: your terminal and keyboard disagree on what “backspace” means.
Worked Example
Using the defaults from the calculator above:
- Terminal type is set to
xterm, which expects erase character 127 (Delete). - Your keyboard sends ASCII 127 when you press Backspace.
- Difference = 127 - 127 = 0 backspaces needed. That works fine.
But if your terminal expects ASCII 8 (Backspace) and your keyboard sends 127, you get 119 backspaces per character. The “28 times” often comes from a terminal that sends an escape sequence for Backspace, and the shell interprets it as a series of spaces or other characters, requiring multiple presses to delete one character.
Why Does This Happen?
The problem arises from a mismatch between the terminal emulator (like GNOME Terminal, Konsole, or PuTTY) and the shell or application (like Bash or Zsh). Each has a setting for the erase character. When they don’t match, pressing Backspace may not delete anything, or it may delete the wrong thing.
In many Linux systems, the default erase character is set to 127 (Delete) for terminals, but some old programs expect 8 (Backspace). When you press Backspace, the terminal sends a byte (often 127), but the program interprets that as “delete the next character” or as a space, so you see a character appear instead of being deleted. To delete it, you press Backspace again, but the same thing happens, so you end up pressing it many times.
The number 28 is not a universal constant; it’s just a common occurrence in specific terminal configurations. It could be that the terminal sends an escape sequence like ^H (ASCII 8) but the shell expects ^? (ASCII 127), so each press produces a visible ^H and you need to press Backspace twice to get rid of that, and so on.
How to Fix It
There are several ways to fix the backspace issue. Try these in order:
- Check your terminal type – Run
echo $TERM. If it’s not set to something likexterm,linux, orscreen, set it withexport TERM=xterm(or the appropriate type). - Use the correct erase key – In Bash, you can set the erase character with
stty erase ^?orstty erase ^H, depending on what your keyboard sends. Try both. - Reset the terminal – Run
resetorstty saneto restore default settings. - Change terminal emulator settings – In most GUI terminals, you can set the Backspace key to send either
Control-H(ASCII 8) orDelete(ASCII 127). Look in the preferences under “Keyboard” or “Profile”. - Use a different shell – If you’re in a weird shell, try a standard one like Bash or Zsh.
Common Misconceptions
One common myth is that pressing Backspace 28 times is a sign of a virus or a broken keyboard. It’s not. It’s purely a configuration issue. Another misconception is that you need to reinstall the OS. You don’t. The fix is simple and usually permanent once you set the terminal type correctly.
Another related issue is when you press Backspace and see ^H or ^? on the screen. That means the terminal is sending a control character that the shell is not interpreting as “delete the previous character”. To fix that, you can use stty erase to tell the shell which character to use as erase.
How to Prevent It
To avoid this problem in the future:
- Always set your
TERMvariable to match your terminal emulator. - When using SSH or remote connections, make sure the remote terminal type matches your local one.
- If you write scripts that change terminal settings, save the old settings and restore them after.
- Use modern terminal emulators that handle Backspace and Delete correctly by default.
Frequently Asked Questions
Why do I see ^H when I press Backspace?
You see ^H because your terminal is sending ASCII 8 (Backspace) but the shell is not set to treat that as an erase character. Run stty erase ^H to fix it.
What is the difference between Backspace and Delete on Linux?
Backspace typically sends ASCII 8 (Control-H) or 127, while Delete sends an escape sequence like ^[[3~. Many shells treat Backspace as erase and Delete as delete-next-character, but it depends on configuration.
Does this happen in all Linux terminals?
No. It depends on the terminal emulator and the shell. Some combinations work out of the box, others don’t. It’s more common in older or minimal setups.
Can I fix it permanently?
Yes. Set the correct erase character in your shell configuration file (like .bashrc) and set the terminal type in your profile. For example, add stty erase ^? to your .bashrc.
Why is it exactly 28 times in my case?
The number 28 is not a standard value. It might be that your terminal sends a sequence that the shell interprets as 28 spaces or 28 delete commands. The exact number depends on the specific escape sequence and the shell’s interpretation.
Is there a command to test my erase character?
Yes. Run stty -a and look for the erase value. It will show something like erase = ^? or erase = ^H. That tells you what the shell expects.