With the command > file.txt 2> file2.txt, where do stdout and stderr go?

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

With the command > file.txt 2> file2.txt, where do stdout and stderr go?

Explanation:
Redirecting stdout and stderr uses the two standard file descriptors: 1 for stdout and 2 for stderr. The operator > sends stdout to a file (and truncates it), while 2> sends stderr to a file (also truncating it). In this line, stdout goes to file.txt and stderr goes to file2.txt. Since there’s no command to run, these redirections apply to the shell itself, so the shell’s own output and error messages will be written to those files instead of the screen. Both files will be created if they don’t exist, and truncated to zero length at the moment the redirections are established.

Redirecting stdout and stderr uses the two standard file descriptors: 1 for stdout and 2 for stderr. The operator > sends stdout to a file (and truncates it), while 2> sends stderr to a file (also truncating it). In this line, stdout goes to file.txt and stderr goes to file2.txt. Since there’s no command to run, these redirections apply to the shell itself, so the shell’s own output and error messages will be written to those files instead of the screen. Both files will be created if they don’t exist, and truncated to zero length at the moment the redirections are established.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy