Unix Shell Input/Output Redirections MCQs
Shell Input/Output Redirections MCQs : This section focuses on "Input/Output Redirections" in Shell Progamming in Unix. These Multiple Choice Questions (MCQ) should be practiced to improve the unix skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. Which symbol is used for taking input from standard input?
A. &
B. %
C. -
D. $
View Answer
Ans : C
Explanation: dashed sign is used for taking input from standard input.
2. Which of the following symbol(s) can be used to redirect the output to a file or another program?
A. |
B. >
C. >>
D. All of the above
View Answer
Ans : D
Explanation: |, >, >> command are used to redirect the output to a file or another program.
3. The >> symbol is used to overwrite the existing file if it exists and | is used to give input to another program.
A. True, False
B. True, True
C. False, True
D. False, False
View Answer
Ans : C
Explanation: The shell provides the >> symbol (right chevron used twice) to append to an existing file and | is used to give input to another program.
4. We can redirect the error message to file named newfile using __________ command.
A. cat foo errorfile
B. cat foo >errorfile
C. cat errorfile>foo
D. cat foo 2>errorfile
View Answer
Ans : D
Explanation: Redirecting standard error requires the 2> symbol.
5. Which symbol is used to redirect error messages to /dev/null?
A. <
B. >
C. %
D. $
View Answer
Ans : B
Explanation: As we redirect our output using > symbol to other files in simple commands, this technique can also be used to redirect error messages to /dev/null file.
6. Which command saves one copy of character stream in a file and store the other to standard output?
A. who
B. tee
C. ls
D. wc
View Answer
Ans : B
Explanation: tee command handles a character stream by duplicating its input.
7. Which of the following is not true about tee command?
A. it is a feature of the shell
B. it is an external command
C. tee command duplicates its input
D. tee is an internal command
View Answer
Ans : A
Explanation: tee command is not a feature of the shell.
8. A _______ is used to redirect input into an interactive shell script or program.
A. document
B. here
C. here document
D. who
View Answer
Ans : C
Explanation: A here document is used to redirect input into an interactive shell script or program.
9. What is the use of pgm < file command?
A. Output of pgm is redirected to file
B. Program pgm reads its input from file
C. Output of pgm is appended to file
D. Takes output from one program, or process, and sends it to another
View Answer
Ans : B
Explanation: pgm < file : Program pgm reads its input from file
10. What is the use of n >& m command?
A. Merges output from stream n with stream m
B. Merges input from stream n with stream m
C. Both A and B
D. None of the above
View Answer
Ans : A
Explanation: n >& m : Merges output from stream n with stream m
Discussion