LoginSignup
1
0

More than 1 year has passed since last update.

Linux: 画面が文字化けしてしまった時にはRESETコマンド

Posted at

たまに必要となるのでメモ。

実施環境:
Linux
[testuser@testhost ~]$ uname -a
Linux testhost 4.18.0-147.8.1.el8_1.x86_64 #1 SMP Thu Apr 9 13:49:54 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[testuser@testhost ~]$ echo $SHELL
/bin/bash

うっかりバイナリファイルをテキスト表示コマンドで開いてしまうと、画面が文字化けして戻らなくなります。

Linux
[testuser@testhost ~]$ head -1 /var/log/wtmp
■tty1tty1■■■■`E
[|es||ser@|es|■os| -]$

このような場合は、resetコマンドを使用することで直すことが可能です。
画面表示上はresetコマンド自体も文字化けしていますが、問題なく実行できます。

Linux
[|es||ser@|es|■os| -]$ rese|
[testuser@testhost ~]$

もっとも、一番良いのはそもそも文字化けさせないことです。
例えば、fileコマンドで開きたいファイルがテキストファイルか事前に確認することで、バイナリファイルをテキスト表示コマンドで開いてしまうことを防げます。

Linux
[testuser@testhost ~]$ file /var/log/README
/var/log/README: ASCII text
[testuser@testhost ~]$ file /var/log/wtmp
/var/log/wtmp: dBase III DBT, version number 0, next free block index 0

lessコマンドのような、テキストファイルかどうかの確認機能が備わっているテキスト表示コマンドを使用することも有効です。

Linux
[testuser@testhost ~]$ less /var/log/wtmp
"/var/log/wtmp" may be a binary file. See it anyway?
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0