0
0
Linux CLIscripting~5 mins

stderr redirection (2>, 2>>) in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ARedirects standard error to error.log, appending it
BRedirects standard output to error.log, appending it
CRedirects standard error to error.log, overwriting it
DRedirects standard output to error.log, overwriting it
Which command appends error messages to a file without deleting existing content?
Acommand 2>> errors.txt
Bcommand >> errors.txt
Ccommand > errors.txt
Dcommand 2> errors.txt
How do you redirect both standard output and standard error to the same file, overwriting it?
Acommand 2> file.txt >&1
Bcommand 2>> file.txt >> file.txt
Ccommand > file.txt 2>> file.txt
Dcommand > file.txt 2>&1
If you want to ignore error messages completely, which redirection would you use?
A2> /dev/null
B2>> /dev/null
C> /dev/null
D2> error.log
What does the number '2' represent in 2>?
AStandard output
BStandard error
CStandard input
DFile descriptor for files
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.