base64

テキスト処理

書き方

base64 [file]

バイトを ASCII の文字に、また元に戻します。暗号ではなく表記の変換で、復号の指定は GNU が -d、古い macOS は -D です。

よく使うオプション

オプション意味
-dDecode. GNU and recent macOS take -d; older macOS needs -D
-wGNU: wrap at N columns, and -w0 keeps it on one line
-iGNU: ignore junk while decoding. On macOS -i names the input file
-oBSD and macOS: write to this file
-bBSD and macOS: wrap the encoded output at N characters

base64 -w0 cert.pem

One long line, no wrapping (GNU).

echo aGVsbG8= | base64 -d

Decodes back to hello.

base64 -i photo.png -o photo.txt

Encoding into a file on macOS.

パイプでつないで使うのが本来の形です。ひとつで全部やるより、三つつないだ方が短くなります。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. base64 は何をしますか。

バイトを ASCII の文字に、また元に戻します。暗号ではなく表記の変換で、復号の指定は GNU が -d、古い macOS は -D です。

Q. どう打ちますか。

base64 [file] — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは5個です。全部は man base64 にあります。このコマンドはテキスト処理の仲間です。

関連するコマンド

man ページ: man base64