OSCP Linux Practice Exam

Access More Questions
If you're trying to redirect stdout or stderr AND throw a long command that's been piped multiple times and includes multiple commands into the background, how do you need to do it?
Correct Answer:
(command; commands | commands) > /dev/null 2>&1 &
Explanation:
The key idea is to treat the whole multi-part command as a single job, so you can redirect both outputs for the entire block and run it in the background. Wrapping the entire sequence in a subshell and then redirecting and backgrounding that subshell ensures stdout and stderr from every part of the long command are sent to /dev/null, not just a piece of it. The syntax shown does exactly that: the long sequence (including an initial simple command followed by a pipeline) is grouped, then its stdout is redirected to /dev/null and 2>&1 sends stderr there as well, and finally the ampersand backgrounds the entire grouped job. This avoids partial redirection and guarantees the whole job runs quietly in the background. In contrast, options without proper grouping or with an incorrect redirection path would either fail to redirect both streams for all parts or would not reliably background the entire composite command.

Access more questions from this quiz

Continue to OSCP Linux Practice Exam for more practice questions and the full quiz experience.

Access More Questions