0
0
Linux CLIscripting~20 mins

/dev/null for discarding output in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Silent Operator
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:00remaining
What is the output of this command?
Consider the command: echo "Hello World" > /dev/null
What will be printed on the terminal after running it?
Linux CLI
echo "Hello World" > /dev/null
AHello World
BError: Permission denied
CNo output (empty)
DThe string 'Hello World' is saved to a file named /dev/null
Attempts:
2 left
💡 Hint
Think about what happens when output is redirected to /dev/null.
💻 Command Output
intermediate
1:00remaining
What happens when you redirect error output to /dev/null?
Given the command: ls nonexistentfile 2> /dev/null
What will be the output on the terminal?
Linux CLI
ls nonexistentfile 2> /dev/null
ACreates a file named /dev/null with error details
BDisplays an error message about nonexistentfile
CLists all files in the current directory
DNo output (empty)
Attempts:
2 left
💡 Hint
Remember that 2> redirects error messages.
📝 Syntax
advanced
1:30remaining
Which command correctly discards both standard output and error?
Choose the command that sends both normal output and error messages to /dev/null, so nothing appears on the terminal.
Acommand &> /dev/null
Bcommand > /dev/null 2> /dev/null
Ccommand 2>&1 > /dev/null
Dcommand 2> /dev/null > /dev/null
Attempts:
2 left
💡 Hint
Look for the syntax that redirects both outputs together.
🔧 Debug
advanced
1:30remaining
Why does this command still show output?
You run: grep 'pattern' file.txt > /dev/null
But you still see error messages if the file does not exist. Why?
ABecause only standard output is redirected, error output is still shown
BBecause /dev/null does not discard output for grep
CBecause the command syntax is invalid
DBecause the file.txt is empty
Attempts:
2 left
💡 Hint
Think about which output streams are redirected.
🚀 Application
expert
2:00remaining
How to silently run a script ignoring all output and errors?
You want to run myscript.sh so that it produces no output or error messages on the terminal. Which command achieves this?
A./myscript.sh > /dev/null
B./myscript.sh > /dev/null 2>&1
C./myscript.sh 2> /dev/null
D./myscript.sh &> /dev/null &
Attempts:
2 left
💡 Hint
Redirect both stdout and stderr to /dev/null.