Stage 2 · Lesson 5 of 9
Redirection and the three streams
Every program has three streams, like three attached to it. (stdin) is what it reads. Standard output (stdout) is its normal results.
Standard error (stderr) is its warnings and error messages. Redirection sends these streams somewhere else. > writes output to a file and replaces what was there.
>> adds to the end of the file instead. < feeds a file in as input, and 2> sends errors to a file. 2>&1 sends errors to the same place as normal output, and /dev/null is a bin that throws output away.
Because the streams are separate, a command can show a warning on screen while its real results go to a file. Scripts, jobs and logs all rely on this.
Common trap> when you meant >>, which silently wipes the file you wanted to add to.
A question to check yourself, an AI practice session and 1 cheat sheet entry come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CourseFreeThe Missing Semester of Your CS Education
MIT · Beginner
MIT's lectures on the shell and shell tools, with exercises after each one
- BookFreeThe Linux Command Line
William Shotts · Beginner
A free book that explains the shell step by step; the first part covers this whole stage
Practise
Keep handy
Also worth your time
- roadmap.sh: Shell / BashGo deeper
The full map of shell and Bash topics, to see what comes after the basics