flybywire flybywire - 6 months ago 15
Linux Question

how do I check in bash whether a file was created more than x time ago?

I want to check in linux bash whether a file was created more than x time ago.

let's say the file is called text.txt and the time is 2 hours.

if [ what? ]
then
echo print "old enough"
fi

Answer

Only for modification time

if test `find "text.txt" -mmin +120`
then
    echo old enough
fi

Or, the same in one line:

#!/bin/bash
find text.txt -mmin +120 -exec echo "old enough" \;

You can use -cmin for change or -amin for access time. As others pointed I don’t think you can track creation time.

Comments