
Here's a preview from my zine, Bite Size Bash!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

read the transcript!
panel 1: unix programs have 1 input and 2 outputs
When you run a command from a terminal, the input & outputs go to/from the terminal by default.
Picture of a program with 1 arrow coming in and 2 arrows out. The arrows are numbered 0, 1, and 2, and there’s a comment: “each input/output has a number, its “file descriptor”)
arrow 0 (coming into program): <
redirects stdin
wc < file.txt
and cat file.txt | wc
both read file.txt
to wc’s stdin
wc < file.txt
cat file.txt
arrow 1 (coming out of program): >
redirects stdout
cmd > file.txt
arrow 2 (coming out of program): 2>
redirects stderr
cmd 2> file.txt
panel 2: 2>&1
redirects stderr to stdout
cmd > file.txt 2>&1
picture of a squiggly 2>&1
which goes from stderr to stdout
(this description of the picture isn’t very good, sorry)
panel 3: /dev/null
your operating system ignores all writes to /dev/null
cmd > /dev/null
picture of stdout going to a trash can (/dev/null
) and stderr still going to the terminal
panel 2: sudo doesn’t addect redirects
your bash shell opens a file to redirect to it, and it’s running as you. So
$ sudo echo x > /etc/xyz
won’t work. do this instead:
$ sudo echo x | tee /etc/xyz
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!