Challenge - 5 Problems
File Descriptor Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the output of this redirection command?
Consider the following bash command:
What will be the output when you run this command in a terminal?
echo 'Hello' 1>&2What will be the output when you run this command in a terminal?
Bash Scripting
echo 'Hello' 1>&2
Attempts:
2 left
💡 Hint
Remember that 1 is standard output and 2 is standard error.
✗ Incorrect
The command redirects standard output (file descriptor 1) to standard error (file descriptor 2). So 'Hello' is printed to standard error, which usually appears on the screen but is a different stream than standard output.
💻 Command Output
intermediate1:30remaining
What happens when redirecting both stdout and stderr to a file?
Given this command:
What will be the content of
ls /nonexistent /tmp > output.txt 2>&1What will be the content of
output.txt after running it?Bash Scripting
ls /nonexistent /tmp > output.txt 2>&1
Attempts:
2 left
💡 Hint
Think about what 2>&1 means after redirecting stdout.
✗ Incorrect
The command first redirects stdout (1) to output.txt, then redirects stderr (2) to wherever stdout is currently going (output.txt). So both outputs go into output.txt.
📝 Syntax
advanced2:00remaining
Which command correctly appends stderr to a file without affecting stdout?
You want to append only the error messages (stderr) of a command to a file named errors.log, while keeping the standard output visible on the screen. Which command does this correctly?
Attempts:
2 left
💡 Hint
Appending means using >> and only redirect stderr (2).
✗ Incorrect
Option D appends stderr (2) to errors.log and leaves stdout untouched, so stdout goes to the screen. Option D redirects both stdout and stderr to errors.log. Option D redirects stderr to errors.log but overwrites it, and stdout to output.log. Option D overwrites errors.log with stdout and appends stderr, mixing outputs.
🔧 Debug
advanced2:00remaining
Why does this redirection command produce unexpected output?
Look at this command:
It produces unexpected output or error. Why?
command 2>&1 > output.txtIt produces unexpected output or error. Why?
Attempts:
2 left
💡 Hint
Order of redirections matters in bash.
✗ Incorrect
In bash, redirections are processed left to right. Here, stderr (2) is redirected to where stdout (1) currently points (usually the screen). Then stdout is redirected to output.txt. So stderr still points to the screen, not the file. This causes unexpected output but no syntax error.
🚀 Application
expert2:30remaining
How to redirect stdout to a file and stderr to another file simultaneously?
You want to run a command so that its standard output goes to out.log and its standard error goes to err.log. Which command achieves this correctly?
Attempts:
2 left
💡 Hint
Use separate redirections for stdout and stderr.
✗ Incorrect
Option C redirects stdout to out.log and stderr to err.log separately. Option B also works but order does not matter here. Option A redirects stderr to stdout and then stdout to err.log, mixing outputs. Option D redirects stderr to stdout, so both go to out.log.