Recall & Review
beginner
What does
2> do in Linux command line?It redirects the standard error (stderr) output of a command to a file, replacing the file's content if it exists.
Click to reveal answer
beginner
How is
2>> different from 2>?2>> appends the standard error output to the file instead of overwriting it.Click to reveal answer
beginner
Why would you use
2> error.log in a script?To save error messages from a command into the file
error.log, so you can review errors later without mixing them with normal output.Click to reveal answer
beginner
What happens if you run
ls /notexist 2> errors.txt?The error message about the missing directory is saved into
errors.txt, and nothing is shown on the screen.Click to reveal answer
intermediate
Can you redirect both standard output and standard error to the same file? How?
Yes. For example,
command > output.txt 2>&1 sends both standard output and standard error to output.txt.Click to reveal answer
What does
2> error.log do?✗ Incorrect
2> redirects standard error and overwrites the file.Which command appends error messages to a file without deleting existing content?
✗ Incorrect
2>> appends standard error to the file.How do you redirect both standard output and standard error to the same file, overwriting it?
✗ Incorrect
Use
> file.txt 2>&1 to redirect both stdout and stderr to the same file.If you want to ignore error messages completely, which redirection would you use?
✗ Incorrect
Redirecting stderr to
/dev/null discards error messages.What does the number '2' represent in
2>?✗ Incorrect
'2' is the file descriptor for standard error.
Explain how to redirect error messages to a file and why it might be useful.
Think about separating error messages from normal output.
You got /4 concepts.
Describe the difference between
2> and 2>> in Linux shell commands.Focus on what happens to the file content.
You got /3 concepts.