In the command 'll asdfkjsdfhk > file.txt 2>&1', which streams are written to file.txt?

Study for the OSCP Linux Exam. Use our flashcards and multiple-choice questions to test your skills. Each query comes with detailed hints and explanations to enhance your preparedness. Get ready to conquer the exam!

Multiple Choice

In the command 'll asdfkjsdfhk > file.txt 2>&1', which streams are written to file.txt?

Explanation:
Redirecting stdout and duplicating stderr to the same destination. In this command, stdout is sent to file.txt with the '>' operator, which opens file.txt for writing and truncates it. The construct 2>&1 redirects the standard error (stderr) to wherever stdout is currently going. Since stdout has been redirected to file.txt, stderr is also written to file.txt. That's why both streams end up in the file. If the order were reversed ('2>&1 > file.txt'), you would typically end up with stdout in the file while stderr remains on the terminal.

Redirecting stdout and duplicating stderr to the same destination. In this command, stdout is sent to file.txt with the '>' operator, which opens file.txt for writing and truncates it. The construct 2>&1 redirects the standard error (stderr) to wherever stdout is currently going. Since stdout has been redirected to file.txt, stderr is also written to file.txt. That's why both streams end up in the file. If the order were reversed ('2>&1 > file.txt'), you would typically end up with stdout in the file while stderr remains on the terminal.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy