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

  • Re: position of parameters
    ... > echo $p1 ... > echo $2 #file2 ... Calling a script with mixed options and arguments could just as ...
    (comp.unix.shell)
  • Re: Possible read/write conflict within awk.
    ... $ echo aa> file1 ... $ echo bb> file2 ...
    (comp.unix.shell)
  • Re: comparing two files last modification date
    ... echo "file1 is newer than file2" ... Thanks the following doesnt quite do what I want. ...
    (comp.unix.shell)
  • Re: isnewer?
    ... if you're worried about filenames with '\n' in them: ...
    (comp.unix.shell)
  • Re: Query in Sort
    ... If File1 has the following records ... File2 only DDD ... send email to listserv@xxxxxxxxxxx with the message: GET IBM-MAIN INFO ... Search the archives at http://bama.ua.edu/archives/ibm-main.html ...
    (bit.listserv.ibm-main)