Article View: mod.std.unix
Article #367Re: file times and shell commands
From: Moderator, John Quarterman
Date: Sun, 02 Nov 1986 00:17
Date: Sun, 02 Nov 1986 00:17
54 lines
2127 bytes
2127 bytes
From: pyramid!utzoo!henry (Henry Spencer)
Date: Fri, 31 Oct 86 21:25:31 CST
> There doesn't appear to be any decent way to compare the last modified
> times of files from the shell...
Before everybody starts inventing their own names for this, it should be
noted that V8 already has a program for this, newer(1). It takes two
filenames as arguments, and exits with status 0 if and only if either
(a) the first exists and the second does not, or (b) both exist and the
first's modification time is at least as recent as the second's. Other-
wise it exits with non-zero status. (The preceding two sentences are
essentially the whole of the manual page for it.)
Relatively few people have V8, but in the absence of any other precedent
for what this facility should like look, it seems reasonable to follow
V8's lead.
Here is an independent rewrite, done from the manual page and not the
code, by me, hereby placed in the public domain:
/*
* newer - is first file newer than second?
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
main(argc, argv)
int argc;
char *argv[];
{
struct stat file1;
struct stat file2;
if (argc != 3) {
fprintf(stderr, "Usage: %s file1 file2\n", argv[0]);
exit(2);
}
if (stat(argv[1], &file1) < 0)
exit(1);
if (stat(argv[2], &file2) < 0)
exit(0);
if (file1.st_mtime >= file2.st_mtime)
exit(0);
exit(1);
}
Henry Spencer @ U of Toronto Zoology
{allegra,ihnp4,decvax,pyramid}!utzoo!henry
Volume-Number: Volume 8, Number 16
Technical Details
Message-ID:
<6196@ut-sally.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!ut-sally!std-unixReferences:
<6177@ut-sally.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!ut-sally!std-unix From: std-unix@ut-sally.UUCP (Moderator, John Quarterman) Newsgroups: mod.std.unix Subject: Re: file times and shell commands Message-ID: <6196@ut-sally.UUCP> Date: Sat, 1-Nov-86 19:17:15 EST Article-I.D.: ut-sally.6196 Posted: Sat Nov 1 19:17:15 1986 Date-Received: Mon, 3-Nov-86 21:56:43 EST References: <6177@ut-sally.UUCP> Organization: IEEE P1003 Portable Operating System for Computer Environments Committee Lines: 54 Approved: jsq@sally.utexas.edu