Linux Command Comparison: test -e vs. test -f

Difference Between test -e and test -f Commands

Question

What is the difference between the commands test -e path and test -f path?

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

C

The commands test -e path and test -f path are used to test the existence and type of a file or directory in Linux.

test -e path is used to test if a file or directory exists at the specified path. It returns true if the path exists, regardless of whether it is a file, directory, or other type of file.

test -f path is used to test if a regular file exists at the specified path. It returns true only if the path exists and is a regular file, which means it is not a directory, device file, socket, or other special file type.

Therefore, the correct answer is C. Both options check the existence of the path, but the -f option also confirms that it is a regular file.