0
0
Linux CLIscripting~5 mins

/dev/null for discarding output in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is /dev/null in Linux?

/dev/null is a special file that discards all data written to it. It acts like a black hole for output.

Click to reveal answer
beginner
How do you discard the standard output of a command in Linux?

By redirecting the output to /dev/null using command > /dev/null.

Click to reveal answer
intermediate
What does this command do? ls > /dev/null 2>&1

It runs ls and discards both standard output and standard error by redirecting them to /dev/null.

Click to reveal answer
beginner
Why would you want to use /dev/null in a script?

To ignore unwanted output or errors so they don’t clutter the screen or logs.

Click to reveal answer
intermediate
What is the difference between command > /dev/null and command &> /dev/null?

command > /dev/null discards only standard output.<br>command &> /dev/null discards both standard output and standard error.

Click to reveal answer
What happens when you redirect output to /dev/null?
AThe output is discarded and not shown
BThe output is saved to a file
CThe output is displayed on the screen
DThe output is sent to the printer
How do you discard both standard output and standard error of a command?
Acommand > /dev/null
Bcommand 2> /dev/null
Ccommand < /dev/null
Dcommand &> /dev/null
Which of these commands discards only the error messages?
Acommand 2> /dev/null
Bcommand > /dev/null 2>&1
Ccommand &> /dev/null
Dcommand > /dev/null
Why might you want to discard output in a script?
ATo save output for later
BTo print output to the screen
CTo prevent cluttering the screen or logs
DTo send output to another program
What does /dev/null behave like?
AA printer device
BA black hole that swallows data
CA file that stores data permanently
DA network socket
Explain how to use /dev/null to discard both output and errors from a command.
Think about redirecting both outputs using > and 2>&1 or &>.
You got /4 concepts.
    Describe a real-life situation where discarding output with /dev/null is helpful.
    Consider running a command repeatedly in a script where output is not needed.
    You got /4 concepts.