A system administrator is running a script that generates a large amount of verbose output to both standard output and standard error. The administrator only needs to check the script's exit code and wants to prevent all output from being displayed on the terminal or written to a log file. Which of the following commands will achieve this?
The correct command is script.sh > /dev/null 2>&1. This command structure first redirects standard output (stdout, file descriptor 1) to the special device file /dev/null, which discards all data written to it. Then, 2>&1 redirects standard error (stderr, file descriptor 2) to the same location as standard output, effectively discarding error messages as well. Redirecting to /dev/zero is incorrect; its primary purpose is to provide a stream of null characters when read. Using a pipe (|) with /dev/null is incorrect because /dev/null is a device file, not a command that accepts standard input. Redirecting to /dev/random is also incorrect as this file is a source for random data and not intended for discarding output.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
What is the purpose of /dev/null in Linux?
Open an interactive chat with Bash
What does the '2>&1' part of the command mean?
Open an interactive chat with Bash
Why can't /dev/zero or /dev/random be used for discarding output?
Open an interactive chat with Bash
CompTIA Linux+ XK0-006 (V8)
System Management
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
IT & Cybersecurity Package Join Premium for Full Access