file-test

Bash -nt — newer modification time

Checks whether the first file has a later modification timestamp than the second, or exists while the second does not. Equal timestamps are false. Timestamps are not a content hash or a proof that one file is more trustworthy. Run the example independently in a fresh private directory. Expected output (one item per line): newer=0; missing-right=0; equal=1.

Formal Syntax & Structure

bash syntaxbash
[[ path1 -nt path2 ]]

Parameters & Attributes

NameTypeDescription
path1pathFirst pathname.
path2pathSecond pathname.

Return Value

exit status

0 for a true condition; 1 for a false condition. Invalid expressions may fail differently.

Working Example

Example Snippetbash
touch -t 202001010000 oldtouch -t 202001020000 new[[ new -nt old ]]; printf 'newer=%s\n' "$?"[[ new -nt missing ]]; printf 'missing-right=%s\n' "$?"[[ new -nt new ]]; printf 'equal=%s\n' "$?"
Bash Reference