Saving output to files
Trang này cần trình duyệt gần đây (hỗ trợ SharedArrayBuffer). Vui lòng cập nhật Chrome, Edge, Firefox hoặc Safari lên phiên bản mới nhất.
English
Catching the output
- Normally a command's output appears on screen. The
>symbol redirects it into a file instead:
echo hello > greeting.txt
- Nothing prints — the text went into
greeting.txt. Read it back withcat 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:
echo line one > notes.txt
echo line two >> notes.txt
- Use
>>when you are building up a file, like a log.
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.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Send the output of echo into a file with >. Write hello thành greeting.txt, then cat it back.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
>> adds a line instead of replacing. Write first thành log.txt, then append second, then show the file.
Độ khó 2/5 · 140 xu + phần thưởng nhỏ khi hoàn thành lần đầu tiên hôm nay
Save the names in names.txt in alphabetical order into a new file sorted.txt, then show sorted.txt.