I'd tried command cat
with an executable file:
cat /bin/ls
Now I can't read any word in this terminal (Linux console). How can I fix it?
I'd tried command cat
with an executable file:
cat /bin/ls
Now I can't read any word in this terminal (Linux console). How can I fix it?
Often times when in a Unix/Linux terminal (Bash) for example you'll use the commands more
or less
or cat
to view a file. When you do this and the file isn't meant to be viewed (such as /bin/ls
) you'll get output like this:
What's going on here is that you just tried to view a file that's a program. An executable which aren't meant to be viewed with standard viewers as I mentioned above.
To fix this issue you can do the following:
reset
and hit returnThis should usually put your terminal back into a more normal mode. I'll mention one more thing, when you do the steps above, you'll by typing them blind into your terminal. So just make sure you're typing it correctly.
As suggested in the comments by @sendmoreinfo you might have better luck using the following commands instead if the above doesn't work:
$ stty sane
$ tput rs1
Incidentally, if you come across a file and aren't sure if it's going to mess up your terminal you can inspect the file using the command file
which will report back the type of file it is.
For example, with /bin/ls
that file shows the following output:
$ file /bin/ls
/bin/ls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, stripped
reset
is not a 100% cure for terminal madness. Try stty sane
followed by tput rs1
.
– sendmoreinfo
Jun 17 '13 at 14:22
stty sane
but never tput
.
– slm♦
Jun 17 '13 at 15:01
I've had an occasion where none of the usual tricks, reset
or stty sane
, worked (after accidentally calling print
on a python bytearray). I had success with method 2 listed on this helpful blog.
I've since created a most helpful alias:
alias fix='echo -e "\033c"'
echo -e "\033c"
helped me to clean up a character-garbled SSH login terminal session that was mixed up after a cat /etc/localtime
.
– Pro Backup
Dec 20 '16 at 21:17
No single prior answer worked for me. But this seemed to do the trick in .bashrc add:
alias fix='reset; stty sane; tput rs1; clear; echo -e "\033c"'
and then when the problem occurs type this (even though you probably can't see it!)
(ctl-c, ctl-c, ctl-c)
fix
Much thanks to the prior submitters. Also, as a side note, the reason that your terminal goes wonky when showing those executable files (or keystores, etc) is that those files often contain binary sequences that are control codes. The control codes may do random things like switch to a graphics character set, set foreground and background colors to the same thing, etc.
tmux
users might be able to send all these commands to their shell, but the resetting doesn't get elevated to the tmux
pane.
Make new tmux window:
ctrl-B c
tmux list-panes
Note the pane number you think is borked, typically 0
. Let's call it PPP
Select the tmux window, where XXX
is the window number which is borked, not necessarily the same as pane number.
ctrl-B XXX
tmux send-key -R -t PPP
You will then see all the commands in the other answers to this question which made it to your shell, but didn't work! Maybe a blind tmux send-key -R -t PPP
will work, but I can't test.
I have almost the same alias as the previous post, with one small change (tput reset
instead of rs1
) and one added command (setterm -reset
):
alias clr='echo -e "\033c" ; stty sane; setterm -reset; reset; tput reset; clear'
Nothing above helped me. However, Jack Wasey mentioned tmux, so I just ran tmux
, exited again and everything was back to normal.
Another solution is:
reset
In addition to other answers advising how to reset the terminal, I figured the corruption cannot be avoided unless properly guarded. So I better send the output to a simple text-friendly converter cat -v
:
docker logs myjenkinscontainer 2>&1 | cat -v
Viewing and editing binary files seems possible with hexdump -C
and vi -R
(:%!xxd -g1
for a hex view and :%!xxd -g1 -r
for saving hex changes).
reset
. – Patrice Levesque Jun 17 '13 at 12:58