LOGBOOK

HELP

Quiz Entry - updated: 2026.06.20

What practical examples demonstrate output redirection?

Pick the operator that matches the goal: > to save, >> to append, 2> to capture errors, 2> /dev/null to silence them, 2>&1 to merge.

Each line below is a real, everyday use of the operators in one place:

# Save current date to file:
date > /tmp/saved-timestamp

# Save first 10 users to file:
head -n 10 /etc/passwd > /tmp/first-10-users

# Save file listing:
ls -a > /tmp/my-file-names

# Combine multiple files:
cat stderr.txt stdout.txt > stderr_and_stdout.txt

# Create a simple text file:
echo "Hello World" > /tmp/hello.txt

# Redirect stderr only:
ls -R /etc/cups 2> stderr

# Redirect stdout and stderr separately:
ls -R /etc/cups > stdout 2> stderr

# Discard stderr:
ls -R /etc/cups > stdout 2> /dev/null

# Both to same file:
ls -R /etc/cups > stdout_stderr 2>&1

# Append both to file:
ls -R /etc/cups >> stdout_stderr 2>&1

Read them as a pattern: the direction operator (>, >>) plus an optional FD number (2) plus a target (a file, /dev/null, or &1). Once you see that grammar, any combination becomes predictable rather than memorized.

Tip: > stdout 2> /dev/null is a classic for "keep the real results, drop the permission-denied noise."

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