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 -ot (older than) operator is a binary file test operator in Bash used within conditional expressions to compare the modification timestamps (mtime) of two files. It evaluates to true (returns exit status 0) if the first file is strictly older than the second file, or if the second file exists but the first file does not.

Syntax

The operator can be used with the Bash test builtin ([ ]) or the Bash extended test keyword ([[ ]]). Note that -ot is a Bash/Ksh extension and is not part of the POSIX standard; it should not be relied upon for strictly portable POSIX sh scripts.
[ file1 -ot file2 ]

# or
[[ file1 -ot file2 ]]

Evaluation Matrix

The operator resolves the comparison based on file existence and the mtime metadata retrieved via the stat system call. It returns false (exit status 1) in any scenario not explicitly evaluating to true.
State of file1State of file2Evaluation Result
ExistsExistsTrue if file1 mtime < file2 mtime. False if file1 mtime >= file2 mtime.
Does not existExistsTrue
ExistsDoes not existFalse
Does not existDoes not existFalse

Technical Characteristics

  • Strict Inequality: The comparison is strictly “older than”. If both files have the exact same modification timestamp, the operator evaluates to false.
  • Symlink Dereferencing: The -ot operator automatically dereferences symbolic links. It compares the mtime of the ultimate target files, not the timestamps of the symlinks themselves. If a symlink points to a non-existent file (a broken link), it is treated as a non-existent file.
  • Timestamp Precision: In Bash 5.0 and later, running on modern filesystems (like ext4, xfs, or zfs), the -ot operator utilizes sub-second (nanosecond) precision (st_mtim) for its comparisons. In Bash 4.4 and earlier, or on legacy filesystems, the comparison is truncated to the nearest second (st_mtime).
  • Metadata Scope: The operator strictly evaluates the modification time (mtime), which updates when file contents change. It does not evaluate the change time (ctime, metadata changes) or access time (atime).
Master Bash with Deep Grasping Methodology!Learn More