Hone

Lessons · Terminal · > (save output)

Sending output to a file

command > file writes the command's output into the file instead of the screen, replacing whatever the file held.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

Saving a report, capturing a command's output for later, making a file from a template: the arrow is how output becomes a file.

How to think about it

One arrow replaces; two arrows add. Decide which you mean before you press Enter, because one arrow cannot be undone.

Worked example

echo first > out.txt
The file holds first.
echo second > out.txt
Replaced.
cat out.txt
second: only the last write survives.

Your turn

Save the file list into files.txt.

ls  files.txt

The trap

Redirecting into the file you are reading from: sort names.txt > names.txt empties the file before sort reads it.

Practise > (save output) on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.