• 0

-nt file test operator in bash


File based condition for if statements in bash

Condition:

[ newerfile -nt olderfile ]

Description:

newerfile was changed more recently than olderfile, or if newerfile exists and olderfile doesn’t.

Example:

if [ file1.txt -nt file2.txt ]; then
    echo "file1.txt is newer than file2.txt;"
fi

Further Reading