[LINUX] What to do if you cat or tail a binary file and the terminal is garbled

When I tried to look at the binary file with cat, the characters were garbled and I got a cold sweat. I will write a coping method and alias setting that summarizes the information lying on the Web.

Garbled characters

無題.png

Remedy 1

reset

Reset the terminal with the reset command. It seems that this may not fix it. In that case, reset ** with a stronger method than the reset command.

Remedy 2

echo ^[c

echo Type "space" "Ctrl + v" "Esc" "c" "Enter".

alias settings

alias clearbin="echo -e '\ec'"

Since it clears what became binary, I simply made it clearbin. I am trying to interpret the escape character with echo -e. e becomes "Esc" and c remains the same.

Trivia (why it's fixed)

I didn't understand why it was fixed in the second solution, so I investigated it.

echo

echo When you press "Space" and "Ctrl + v", it looks like this. "Ctrl + v" is a preparation for inputting "Esc", and nothing is displayed when it is a single unit. It seems that this preparation is necessary because you can not enter by just pressing "Esc".

echo ^[

Then press "Esc" and it will look like this.

echo ^[c

In addition to that, enter "c" It seems that "Esc" and "c" can reset the terminal more powerfully than the reset command. Finally, press "Enter" to finish.

How to represent "Esc"

It seems that "Esc" can be represented in octal or hexadecimal when set to alias.

For octal numbers

alias clearbin="echo -e '\033c'"

For hexadecimal numbers

alias clearbin="echo -e '\0x1bc'"

Helpful articles

About ANSI escape sequences What does printf(“\033c” ) mean?

Recommended Posts

What to do if you cat or tail a binary file and the terminal is garbled
What to do if you grep a text file and it becomes Binary file (standard input) matches
What to do if (base) is displayed at the beginning of the Mac terminal
What to do when PyCharm font is strange or garbled
What to do if you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3
What to do if you get a minus zero in Python
What to do if you get a UnicodeDecodeError with pip install
What to do if the inode is exhausted on EC2 Linux
What to do if you can't use the trash in Lubuntu 18.04.
[Django] What to do if the model you want to create has a large number of fields
What to do if the user name is changed and the pyenv library path does not pass
What to do if there is a decimal in python json .dumps
What to do if you can't find PDO in Laravel or CakePHP
What to do if the Pipenv environment is corrupted by updating Homebrew
[Introduction to Python] What is the difference between a list and a tuple?
What to do if you get lost in file reference with FileNotFoundError
What to do if you get a TypeError with numpy min, max
What to do if you get a "Wrong Python Platform" warning when using Python with the NetBeans IDE
I want to receive the configuration file and check if the JSON file generated by jinja2 is a valid JSON
What to do if you get the message "" ~ .pkg "is corrupted and cannot be opened" when installing wxPython on Mac OS X
A story about what to do when a bad interpreter: Not such file or directory appears in Anaconda3 and how to investigate the cause.
What to do if you can't pipenv shell
What to do if you get a "No versions found" error in pipenv
What to do if the latest Jupyter Notebook and nb extensions don't work
[Note] What to do if the Qt library conflicts between pyqt and opencv
Is Parallel Programming Hard, And, If So, What Can You Do About It?
What to do if a version error occurs in the selenium Chrome driver
What to do if you get the error Input contains NaN, infinity or a value too large for dtype ('float64'). In machine learning
What to do if you can't pip install mysqlclient
What to do if your Jupyter Notebook for beginners asks for a password or token
No module named What to do if you get'libs.resources'
What to do if the Microsoft Store opens even if you run python on Windows
ModuleNotFoundError: No module What to do if you get'tensorflow.contrib'
What is a terminal?
What to do if you get a memory error when converting from PySparkDataFrame to PandasDataFrame
What to do if pvcreate produces a lot of WARNING and cannot be created
What to do when gdal_merge creates a huge file
What to do if ENOENT: no such file or directory appears during npm install
What to do when only the window is displayed and nothing is displayed in pygame Note
What to do if the progress bar is not displayed in tqdm of python
What to do if a UnicodeDecodeError occurs in pip
How to install and use pyenv, what to do if you can't switch python versions
What is pip and how do you use it?
Output a binary dump in binary and revert to a binary file
What to do if you get the error "Error: opencv3: Does not support building both Python 2 and 3 wrappers" when installing openCV 3
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
What to do if pyenv is not enabled (zsh)
What to do if you can't hit the arrow keys in the Python interactive console
What to do if you run python in IntelliJ and end with an error
What to do if you can't create a virtual environment using venv even though you're following the Django official website
What to do if you install openCV3 and make a symbolic link, but when you do "import cv2", "No module named'cv2'" appears
What to do if the library doesn't load when you run it in PyCharm, even though it works fine on terminal
What to do if you have corrected the mistake in the IP address of the zone file but cannot connect to the DNS server
[* CentOS 6.10] What to do if you cannot add the IUS Community Project repository on CentOS 6.5 (VirtualBox)
Make a note of what you want to do in the future with Raspberry Pi
What to do if the image is not displayed using matplotlib etc. in the Docker container
What to do if you get Swagger-codegen in python and Import Error: No module named
What to do if you get a Cannot retrieve metalink for repository error in yum
What is the difference between a symbolic link and a hard link?
What to do if the package dependency cannot be repaired
What to do if you are addicted to Windows character code