nerdexam
Linux_Foundation

LFCS · Question #118

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

The correct answer is C. Both options check the existence of the path. The -f option also confirms that it is a regular file. The test -e option checks for the existence of any file or directory, while test -f specifically checks for the existence of a regular file.

Submitted by eva_at· Apr 18, 2026Essential Commands

Question

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

Options

  • AThey are equivalent options with the same behaviour.
  • BThe -f option tests for a regular file. The -e option tests for an empty file.
  • CBoth options check the existence of the path. The -f option also confirms that it is a regular file.
  • DThe -f option tests for a regular file. The -e option tests for an executable file.

How the community answered

(37 responses)
  • A
    3% (1)
  • B
    3% (1)
  • C
    89% (33)
  • D
    5% (2)

Why each option

The `test -e` option checks for the existence of any file or directory, while `test -f` specifically checks for the existence of a regular file.

AThey are equivalent options with the same behaviour.

The options `-e` and `-f` are distinct; `-e` checks for any existence, while `-f` checks for a regular file.

BThe -f option tests for a regular file. The -e option tests for an empty file.

The `-e` option checks for general existence, not for an empty file; `test -s` is used to check for non-empty files.

CBoth options check the existence of the path. The -f option also confirms that it is a regular file.Correct

The `test -e path` expression returns true if the specified `path` exists, regardless of whether it's a regular file, directory, symlink, or other file type. Conversely, `test -f path` returns true only if the `path` exists *and* refers specifically to a regular file (i.e., not a directory or other special file type).

DThe -f option tests for a regular file. The -e option tests for an executable file.

The `-e` option checks for general existence, not for an executable file; `test -x` is used to check for executable permissions.

Concept tested: `test` command file type checks (`-e`, `-f`)

Source: https://man7.org/linux/man-pages/man1/test.1.html

Topics

#test command#file existence#regular file#shell scripting

Community Discussion

No community discussion yet for this question.

Full LFCS Practice