Three Streams
What this is. Every command has three connections to the outside world, and once you can name them, redirection stops being magic.
Standard input, where it reads from. Your keyboard by default.
Standard output, where results go. Your screen by default.
Standard error, where problems go. Also your screen by default, which is why they look the same until you separate them.
The operators.
> sends standard output into a file, replacing whatever was there.
>> sends it into a file, appending to the end.
< feeds a file into standard input.
2> sends standard error somewhere separately.
✦ The greater-than sign truncates without asking
command > file.txt empties that file the moment the command starts, before it has produced anything. Point it at a file you needed and the contents are gone, even if the command then fails. This is why >> exists and why people reach for it by default when appending to a log. There is no confirmation and no undo.
Mark this lesson complete
Signed in, your progress follows you to every device.