LPI Linux Essentials (D281 and C851) Practice Exam 2025 – All-in-One Guide to Master Your Certification!

Question: 1 / 400

Why is the file data.txt empty after executing sort data.txt > data.txt?

Because sort cannot sort text files, only binary files

Because sort detects that both files are the same

Because the file gets truncated before sort is executed

The reason the file data.txt is empty after executing the command sort data.txt > data.txt is that the file gets truncated before the sort operation is executed. When using the redirection operator (>) in a shell command, the file on the right side of the operator is cleared or truncated to zero length immediately before the command on the left side is run. Consequently, the output of the sort command is intended to be placed in data.txt, but since the file has already been emptied, the output has nowhere to go and results in data.txt being empty after execution.

Understanding this behavior is crucial when working with shell commands and file redirection, as it illustrates the importance of managing file contents carefully to prevent data loss when redirecting outputs.

Get further explanation with Examzify DeepDiveBeta

Because the file gets executed before sort is truncated

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy