Exam LFCS All QuestionsBrowse all questions from this exam
Question 43

Which of the following statements is correct regarding the command foo 1> bar?

    Correct Answer: B

    The command 'foo 1> bar' indicates that the standard output (stdout) from the command 'foo' is redirected to the file 'bar', and it will overwrite the contents of 'bar' if it already exists. In Unix-like operating systems, '>' is used for redirecting stdout to a file, and by default, '1' refers to stdout, so it is often omitted. Therefore, 'foo > bar' has the same effect as 'foo 1> bar'. None of the other options correctly describe the behavior of this command.

Discussion
BorbzOption: B

Correct. 0 - stdin 1 - stdout 2 - stderr

Borbz

> replaces >> Appends

BuruguduystunstugudunstuyOption: B

The correct statement regarding the command 'foo 1> bar' is that the stdout from the command 'foo' overwrites the file 'bar'. Option B is the correct answer. In Bash, the '>' symbol is used to redirect output from a command to a file. The number '1' specifies the standard output file descriptor. Therefore, the command 'foo 1> bar' redirects the standard output of the command 'foo' to the file 'bar', overwriting the file if it already exists. The other statements are not correct: Option A: The stdout from the command 'foo' is not appended to the file 'bar'. It overwrites the file. Option C: The command 'foo' does not receive its stdin from the file 'bar'. Option D: The command 'foo' does not receive its stdin from the stdout of the command 'bar'. Option E: The stderr from the command 'foo' is not saved to the file 'bar'. To redirect the stderr of a command to a file, you can use the command 'foo 2> bar'.