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
Cathern
11 days ago
I feel like C explains the behavior perfectly.
upvoted 0 times
...
Charlette
17 days ago
D is incorrect. Redirection works with >.
upvoted 0 times
...
Bronwyn
22 days ago
B could be true if there were no matches, but the file is still empty.
upvoted 0 times
...
Rory
27 days ago
A is also a possibility, but I lean towards C.
upvoted 0 times
...
Earnestine
1 month ago
Agreed, C makes the most sense.
upvoted 0 times
...
Evangelina
1 month ago
I think it's C. The file gets overwritten before sed runs.
upvoted 0 times
...
Rosio
1 month ago
B doesn't make sense, sed would just output the original content if no match.
upvoted 0 times
...
Bernadine
2 months ago
No way, D is wrong. Redirection works with >.
upvoted 0 times
...
Lenna
2 months ago
Wait, I thought it was A at first. That’s surprising!
upvoted 0 times
...
Donette
2 months ago
Totally agree, C is the right answer.
upvoted 0 times
...
Idella
2 months ago
It's C! The file gets cleared before sed runs.
upvoted 0 times
...
Na
2 months 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
2 months 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
3 months 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
3 months 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