base64
テキスト処理
書き方
base64 [file]バイトを ASCII の文字に、また元に戻します。暗号ではなく表記の変換で、復号の指定は GNU が -d、古い macOS は -D です。
よく使うオプション
| オプション | 意味 |
|---|---|
| -d | Decode. GNU and recent macOS take -d; older macOS needs -D |
| -w | GNU: wrap at N columns, and -w0 keeps it on one line |
| -i | GNU: ignore junk while decoding. On macOS -i names the input file |
| -o | BSD and macOS: write to this file |
| -b | BSD and macOS: wrap the encoded output at N characters |
例
base64 -w0 cert.pemOne long line, no wrapping (GNU).
echo aGVsbG8= | base64 -dDecodes back to hello.
base64 -i photo.png -o photo.txtEncoding into a file on macOS.
パイプでつないで使うのが本来の形です。ひとつで全部やるより、三つつないだ方が短くなります。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. base64 は何をしますか。
バイトを ASCII の文字に、また元に戻します。暗号ではなく表記の変換で、復号の指定は GNU が -d、古い macOS は -D です。
Q. どう打ちますか。
base64 [file] — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは5個です。全部は man base64 にあります。このコマンドはテキスト処理の仲間です。
関連するコマンド
man ページ: man base64