Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Linux Foundation LFCS Exam - Topic 2 Question 115 Discussion

When running the commandsed -e "s/a/b/" /tmp/file >/tmp/fileWhile /tmp/file contains data, why is /tmp/file empty afterwards?
C) When the shell establishes the redirection it overwrites the target file before the redirected command starts and opens it for reading.
A) The file order is incorrect. The destination file must be mentioned before the command to ensure redirection.
B) The command sed did not match anything in that file therefore the output is empty.
D) Redirection for shell commands do not work using the > character. It only works using the | character instead.

Linux Foundation LFCS Exam - Topic 2 Question 115 Discussion

Actual exam question for Linux Foundation's LFCS exam
Question #: 115
Topic #: 2
[All LFCS Questions]

When running the command

sed -e "s/a/b/" /tmp/file >/tmp/file

While /tmp/file contains data, why is /tmp/file empty afterwards?

Show Suggested Answer Hide Answer
Suggested Answer: C

Contribute your Thoughts:

0/2000 characters
Bernadine
2 days ago
No way, D is wrong. Redirection works with >.
upvoted 0 times
...
Lenna
8 days ago
Wait, I thought it was A at first. That’s surprising!
upvoted 0 times
...
Donette
13 days ago
Totally agree, C is the right answer.
upvoted 0 times
...
Idella
18 days ago
It's C! The file gets cleared before sed runs.
upvoted 0 times
...
Na
23 days ago
I definitely remember that using > overwrites the file, but I don't think option D is correct since > is a valid redirection operator.
upvoted 0 times
...
Art
28 days ago
I feel like option A could be a possibility, but I can't recall if the order really matters in this case.
upvoted 0 times
...
Tamala
1 month ago
I think I saw a similar question about sed and file redirection in practice. It might be option C, but I'm not completely confident.
upvoted 0 times
...
Ozell
1 month ago
I remember something about how redirection works in the shell, but I'm not entirely sure if it overwrites the file before the command runs.
upvoted 0 times
...

Save Cancel