CompTIA Linux+ Powered by LPI (LX0-103) — Question 18

When running the command -
sed -e "s/a/b/" /tmp/file >/tmp/file
while /tmp/file contains data, why is /tmp/file empty afterwards?

Answer options

Correct answer: C

Explanation

The correct answer is C because when the shell processes the redirection, it truncates the target file before executing the 'sed' command, leading to an empty file. Options A and D are incorrect as they misrepresent how redirection works, while B is wrong because the command does not need to match anything to cause the file to be empty; the redirection itself is the issue.