Saving output to files · 出力をファイルに保存する
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · このページには最新のブラウザ(SharedArrayBuffer対応)が必要です。Chrome、Edge、Firefox、Safariを最新バージョンに更新してください。
English
Catching the output
- Normally a command's output appears on screen. The
>symbol redirects it into a file instead:
- Nothing prints — the text went into
greeting.txt. Read it back withcat greeting.txt.
日本語
出力をキャッチする
- 通常、コマンドの出力は画面に表示されます。
>の記号はそれをリダイレクトしてファイルに送ります:
echo hello > greeting.txt
- 何も表示されません — テキストは
greeting.txtの中に入りました。cat greeting.txtで読み返してください。
English
Replace vs add
>replaces the file's contents (or creates it if new).>>appends — it adds to the end, keeping what was there:
- Use
>>when you are building up a file, like a log.
日本語
上書き vs 追加
>はファイルの内容を上書きします(または新しいファイルを作成します)。>>は追記します — 末尾に加えて、それまであった内容も残します:
echo line one > notes.txt
echo line two >> notes.txt
- ログのようなファイルを作っている場合は、
>>を使用してください。
English
Why this matters
- Saving output lets you keep results, build files from commands, and feed one program's output to another.
- ⚠️ Watch out:
>on an existing file erases it first. Use>>when you mean "add".
日本語
なぜこれが重要なのか
- 出力を保存することで、結果を残したり、コマンドからファイルを構築したり、あるプログラムの出力を別のプログラムに渡したりできます。
- ⚠️ 注意:既存のファイルに対して
>を使うと先に消去されます。「追加」を意図している場合は>>を使用してください。
English
Common mistakes
>overwrites a file;>>adds to the end.>on a file that already exists erases it first.
日本語
よくあるミス
>はファイルを上書きし、>>は末尾に追加します。- 既存のファイルに対して
>を使うと、先に消去されます。
Send the output of echo into a file with >. Write hello into greeting.txt, then cat it back. · echo の出力を > を使ってファイルに送る。hello を greeting.txt に書き込み、cat で戻す。
>> adds a line instead of replacing. Write first into log.txt, then append second, then show the file. · >> は置き換えず 追加 する。first を log.txt に書き込み、second を追記し、ファイルを表示する。