Skip to Content

A stick figure smiling

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!

Image of a comic. To read the full HTML alt text, click "read the transcript".

browse more comics! get the zine!
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 (represented by a box with a smiley face) 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

Illustration of cmd, represented by a box with a smiley face. There is one arrow, labelled “sdout(1)”, leading to a box labelled “file.txt”. There is a second arrow coming out of cmd, labelled “stderr(2)”. Then, there’s a squiggly third arrow, labelled “2>&1”, that leads from “stderr(2)” to “file.txt”.

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!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2024 | All rights reserved (see the FAQ for notes about licensing)