nkfによる文字コードの変換

# nkf --guess index.php
EUC-JP

ファイルのエンコードを確認します。

# nkf -Ew index.php

-Eは入力形式をEUC-JPに、-wは出力形式をUTF8に指定します。index.phpを読み込み、変換した結果を標準出力に出力します。

# nkf -Ew **/*.php | nkf --guess
# nkf -Ew --overwrite **/*.php

--overwriteは元のファイルを変換結果で置換します。

# nkf -Ew **/*.php | nkf --guess
BINARY
# nkf -Ew *.php | nkf --guess
UTF-8
# cat *.php | nkf --guess
UTF-8
# grep 'EUC-JP' *.php
# nkf -Sw --overwrite index.html