LOGBOOK

HELP

Quiz Entry - updated: 2026.06.20

How do you redirect both stdout and stderr to separate files?

Give each stream its own target: cmd > out.txt 2> err.txt puts normal output in one file and errors in another.

You can redirect both streams in a single command by listing both operators. They're independent, so results and errors never mix:

ls > out.txt 2> err.txt
# out.txt  -> the directory listing
# err.txt  -> empty (nothing failed)

cat missing.txt > out.txt 2> err.txt
# out.txt  -> empty (cat produced no normal output)
# err.txt  -> cat: missing.txt: No such file or directory

Since bare > already means stdout, > out.txt 2> err.txt and 1> out.txt 2> err.txt are identical — write the 1 only if you find it clearer.

Why bother? Keeping the two files apart is great for scripts and cron jobs: you scan err.txt to see if anything went wrong, while out.txt holds the clean result you actually wanted.

Gotcha: don't send both streams to the same filename with two separate redirects (> f 2> f) — they open f independently and clobber each other. To merge two streams into one file you use 2>&1, covered separately.

From Quiz: LIOS / Reading and Editing Files from the Command Line | Updated: Jun 20, 2026