You work as the Network Administrator for McNeil Inc. The company has a Linux-based network.
You are working as a root user on Red Hat operating system. You are currently running a program
named My_program. You are getting some error messages while executing the program. You
want to redirect these error messages to a file named file2 rather than being displayed on the
screen.
Which of the following tools should you use to accomplish the task?
A.
My_program >> file2
B.
My_program 2> file2
C.
My_program 2>> file2
D.
My_program > file2
Explanation:
This command will execute a program named My_program and whatever errors are generated
while executing that program will all be added to a file named file2 rather than being displayed on
the screen.
What is redirection of STDIN, STDOUT, STDERR in Linux?
Redirection means diverting data from their normal destination to another. Whenever a program is
executed on terminal some output is displayed at the shell prompt. In case a user does not want
that output to appear in the shell window, the user can redirect it elsewhere. The user can redirect
the output into a file, printer, etc.
Not only the output of programs is redirected, but also input of a program and error messages are
redirected to a file.
Common Redirection operators are as follows:Answer option D is incorrect. This command will direct the standard output of My_program to file2.
Answer option A is incorrect. This command will append the standard output of My_program to
file2.
Answer option C is incorrect. This command cannot be applied in this scenario.
D