10
4

More than 3 years have passed since last update.

[Linux]ファイル閲覧時の文字化け対処法

Posted at

ファイル閲覧時に文字化けさせずに閲覧する方法の覚書き

環境

  • CentOS Linux release 7.9.2009

手順

1. 対象ファイルの文字コードを調べる

(1) 以下のコマンドを実行

nkf --guess ファイル名
  • ファイル名がhoge.phpの場合は以下の通り
nkf --guess hoge.php

2. 対応する文字コードでファイルを開く

(1) 以下のコマンドを実行

cat ファイル名 | nkf 文字コード指定(入力関係)
  • ファイル名がhoge.php, 「1. 対象ファイルの文字コードを調べる」の結果が「EUC-JP」の場合は以下の通り
cat hoge.php | nkf -E

※nkfコマンドの入力関係のオプション

オプション 文字コード
-J ISO-2022-JP
-E EUC-JP
-S Shift-JIS
-W,-W8 UTF-8
-W16 UTF-16(リトルエンディアン)
-W16B UTF-16(ビッグエンディアン)

終わりに

最近、文字化けで読めない問題によく遭遇するので、すぐ対応できるようにしました

参考

10
4
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
10
4