Re: comparing two files last modification date



2008-11-13, 06:35(-08), puzzlecracker:
I have two files, say file1 and file2, I would like to find out which
of these two files was modified last.
[...]

Some shells (ksh, zsh, bash) have [[ file1 -nt file2 ]].

In the standard toolchest, you've got "find -newer" and "ls -t"

if find file1 -prune -newer file2 -print | grep -q .; then
echo "file1 is newer than file2"
fi

Or:

NL='
'
case $(ls -td file1 file2) in
("file1${NL}file2") echo "file1 is not older than file2";;
("file2${NL}file1") echo "file2 is not older than file1";;
(*) echo >&2 error;;
esac


--
Stéphane
.



Relevant Pages