compare file's date bash compare file's date bash bash bash

compare file's date bash


You can compare file modification times with test, using -nt (newer than) and -ot (older than) operators:

if [ "$file1" -ot "$file2" ]; then    cp -f "$file2" "$file1"fi


Here is a POSIX solution:

find -name file2 -newer file1


Or even shorter and nicer, look at man stat:

stat -c %y file