101-500 Exam QuestionsBrowse all questions from this exam

101-500 Exam - Question 55


Which of the following commands redirects the output of ls to standard error?

Show Answer
Correct Answer: C

To redirect the output of the 'ls' command to standard error (stderr), you use the file descriptor '2'. The 'ls >&2' command accomplishes this by redirecting the standard output (stdout) of 'ls' to standard error. Other options either do not use the correct redirection symbol or attempt to use invalid or incorrect syntax. For example, 'ls >-1' creates a file named '-1', 'ls <<err' is syntactically incorrect, 'ls >>2' appends to a file named '2', and 'ls |error' attempts to pipe the output to a non-existent 'error' command.

Discussion

3 comments
Sign in to comment
CuriousLinuxCatOption: C
Jul 3, 2021

@okamigo, E is absolutely false because it isn't even using the re-directional symbol (>). The correct answer is C. D is wrong because the append symbol (>>) cannot append to STDERR(2). It needs a file to append the out of 'ls' to.

okamigoOption: E
Apr 11, 2021

C it's not correct answer I think E it wright answer

anhcq
Nov 14, 2021

nope, E ls |error, this command redirect output of ls command to error command which is not found. answer C is correct

SScott
Nov 17, 2021

C is correct: ls>&2 sends the ls output to the 2 (stderr) location A, B, D, and E are wrong: ls>-1 creates a file -1 that is the output of ls <<ERR sets the ERR string as the end of input ls>>2 would append to a file '2' ls |error is an invalid command

NinymoOption: C
Mar 24, 2024

Answer: C