Comparing modified times of files
Rob Lemley
rob at b15.ingr.com
Sat Mar 9 08:58:03 AEST 1991
In <SCOTTP.91Mar8093523 at bwdlh504.bnr.ca> scottp at 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
More information about the Comp.unix.shell
mailing list