Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!infonode!ingr!b15!rob From: rob@b15.ingr.com (Rob Lemley) Newsgroups: comp.unix.shell,bnr.general Subject: Re: Comparing modified times of files Message-ID: <1991Mar8.225803.8397@b15.ingr.com> Date: 8 Mar 91 22:58:03 GMT References: Distribution: comp Organization: Intergraph Huntsville Lines: 34 In scottp@bwdlh504.bnr.ca (Scott Pace) writes: >I would like to be able to compare two files' time stamps, to see which one >is the oldest (or newest). How can I do this with sh? This script will print the name of the newest file: # # newer file1 file2 # # print the name of the newest file on standard output # if files are the same age, nothing printed. # find "$1" -name "$1" -newer "$2" -print find "$2" -name "$2" -newer "$1" -print The -name options are used to help avoid problems if directories are given. There will be other problems if the files are directories. You could use just one find command, but then you wouldn't know for sure if the files had the same date. Another possibility is using "make": echo "file1: file2" | make -f - make will print `file1' is up to date. If $1 is newer or same age as $2 -- Rob