What is the effect of echo test > file.txt 2>&1?

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

What is the effect of echo test > file.txt 2>&1?

Explanation:
This is about how shell I/O redirection works. The command first sends stdout to file.txt with > file.txt. Then 2>&1 redirects stderr to wherever stdout is currently going. Since stdout is already going to file.txt, stderr is redirected there as well. So both stdout and stderr end up in file.txt. If the order were reversed, the result could be different, but with this left-to-right processing, both streams go to the file.

This is about how shell I/O redirection works. The command first sends stdout to file.txt with > file.txt. Then 2>&1 redirects stderr to wherever stdout is currently going. Since stdout is already going to file.txt, stderr is redirected there as well. So both stdout and stderr end up in file.txt. If the order were reversed, the result could be different, but with this left-to-right processing, both streams go to the file.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy