Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The -e operator is a unary file test operator in Bash used to evaluate the existence of a file path. It returns a boolean true (exit status 0) if the specified path exists within the filesystem, regardless of the underlying file type (e.g., regular file, directory, symbolic link, named pipe, socket, or device node). If the path does not exist, it returns false (exit status 1).

Syntax

The operator can be invoked using the standard POSIX test command, the classic test brackets [ ], or the Bash-specific extended test brackets [[ ]].

# POSIX test command
test -e /path/to/target


# Classic test (built-in)
[ -e /path/to/target ]


# Extended test keyword (Bash-specific)
[[ -e /path/to/target ]]

Technical Behavior

  • Exit Status: Like all Bash test operators, -e does not output text to stdout. It communicates strictly through the shell’s exit status ($?), yielding 0 for success and 1 for failure.
  • Symbolic Link Dereferencing: When applied to a symbolic link, the -e operator dereferences the link and evaluates the existence of its target. Consequently, if the path points to a broken symbolic link (an orphaned link pointing to a non-existent file), -e evaluates to false.
  • Path Resolution and Permissions: The operator requires execute (x) permissions on all parent directories leading up to the target file. If the shell process lacks the necessary permissions to traverse the directory tree to the target, -e will evaluate to false, even if the file physically exists on the disk.
  • Scope: The -e operator is the most generic file test operator. It is strictly concerned with namespace occupation. It does not differentiate between file types, unlike -f (which restricts evaluation to regular files) or -d (which restricts evaluation to directories).
Master Bash with Deep Grasping Methodology!Learn More