The Backspace key isn’t something you normally think about too much, but sometimes you might find it doesn’t work correctly in the terminal, especially when logged in to a remote machine, echoing «^H» instead of erasing what you’ve typed.
Fortunately, this is easy to fix with a simple command.
What Are These Weird Characters?
You may notice this problem when you log in to remote machines over SSH, ones that run non-Linux Unix operating systems, particularly proprietary systems like Oracle’s Solaris. A lot of older computer terminals used a different control character for Backspace than today, using «Ctrl + H.»
Modern terminals use «Ctrl + ?» for Backspace. Most systems will recognize the latter as Backspace these days as physical terminals have largely been replaced by terminal emulators on PCs, but you may still run into systems that haven’t been upgraded and still expect «Ctrl + H.»
This is one reason you’ll see old Unix hands jokingly use «^H» in messages in the same way people use ironic strikethroughs to indicate «Oops, you weren’t supposed to see that!» They might say something like «I love Linux system mangling^H^H^H^H^H^H^Hadministration.»
Checking Terminal Settings with stty
You can check what control characters the system uses with the stty command. The -a flag will give a human-readable output of the control characters.
stty -a
Look for the «erase» character. If it says «^H,» then it uses the older Backspace character. Fortunately, you can also fix this with the stty command.
Setting the Erase Character
You can set the erase character to the one your computer uses with this simple command:
stty erase '^?'
Try this and see if the Backspace key works correctly. You can put this in the shell’s startup file, such as .bashrc for Bash and .zshrc for Zsh to have this set automatically when you log into the system.
Similar to the Backspace key, you can fix the issue using the stty command if Tab doesn’t work in the terminal.
Now Your Backspace Key Works in the Linux Terminal
Now that you’ve sorted out the Backspace key issue in the Linux terminal, you can really get to work.
If you’re using the terminal to log in to remote systems, you can be even more productive with the combination of tmux and Mosh, letting you create sessions that can keep you connected forever.
Read Next
About The Author