How to verify that file2 is newer than file1 in bash

bash

How can I verify that file2 was last modified after file1?

In this example, perl was modified more recently than stack. Is there a bash or Linux command that can compare these files based on the modification time?

-rw-r--r--    1 root     root         1577 Sep  7 22:55 stack
-rwxr-xr-x    1 root     root          626 Sep  7 23:10 perl

Best Answer

Found it here

for f in /abcd/xyz* do
   [ "$f" -nt /abcd/test.txt ] && echo "file f$ found" done
Related Question