Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/17/84; site sol1.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!gatech!akgua!sol1!john From: john@sol1.UUCP (john) Newsgroups: net.sources Subject: ftimes (file modification times) with human-readable format Message-ID: <370@sol1.UUCP> Date: Sat, 9-Nov-85 17:48:56 EST Article-I.D.: sol1.370 Posted: Sat Nov 9 17:48:56 1985 Date-Received: Mon, 11-Nov-85 05:43:15 EST Reply-To: john@sol1.UUCP (John Korsmeyer) Organization: THE SOLUTION, Lincoln, NE Lines: 144 The following is a slightly modified version of Ken Yap's ftimes. This version allows for the 'v' option which will print the output in human readable format ie. Sat Nov 9 16:46:08 CST 1985. The modified manual page is also included. --------------- CUT ME HERE ---------------------- #!/bin/sh cat >ftimes.1 <<'------ EOF ------' .TH FTIMES 1 .SH NAME ftimes \- display access, change and modify times of a file .SH SYNOPSIS .B ftimes [ \fB\-acmv\fR ] file .SH DESCRIPTION .IR Ftimes displays the access, change and modify times of a file in seconds past the epoch (1 January 1970). This is useful for making decisions in shell scripts. .PP Flags a, c and m select the corresponding times. The v flag displays output in human readable form ie. Sat Nov 9 16:40:22 CST 1985 If no option, or only the v flag is selected, the default is the modify time. .PP Example: .br .nf .in +5 if test `ftimes RCS/file,v` -gt `ftimes file` then co file fi .in -5 .fi is a shell script to check out a RCS file if a newer version has been checked in since the working version was created. .SH AUTHOR Ken Yap (University of Rochester) ------ EOF ------ ls -l ftimes.1 cat >ftimes.c <<'------ EOF ------' /* ** ftimes [-acm] file ** ** Output the access, change and modify times of the file. ** If no flag is selected, the default is the modify time. ** ** This is public domain software. It may be freely distributed, ** modified and used. Please use it for peaceful purposes ** and also not for profit. ** ** Bug reports and comments to: ** ** Ken Yap (ken@rochester.{arpa,uucp}) ** ** I do not promise any sort of support or warrant the ** suitability of this software for any purpose whatsoever. ** ** Last modified: ** ** Ken Yap (ken@rochester.{arpa,uucp}) 26th Sep 1985 ** ** Added verbose -v option to output in human readable format ** John Korsmeyer (sol1!john) 9th Nov 1985 */ #include#include #include #include static int aflag = 0, /* display access time */ cflag = 0, /* display change time */ mflag = 0; /* display modify time */ verbose = 0; /* display in human readable format */ main(argc, argv) int argc; char *argv[]; { register int n, errflag = 0; struct stat sb; extern int optind; /* defined in getopt */ extern char *optarg; /* defined in getopt */ int getopt(), stat(); while ((n = getopt (argc, argv, "acmv")) != EOF) { switch (n) { case 'a': aflag++; break; case 'c': cflag++; break; case 'm': mflag++; break; case 'v': verbose++; break; default: errflag++; break; } } argc -= optind; if (errflag || argc != 1) { fprintf(stderr, "usage: %s [-acm] file\n", argv[0]); exit(2); } argv += optind; if (stat(argv[0], &sb) < 0) { perror(argv[0]); exit(1); } if (!aflag && !cflag) mflag = 1; /* at least mod time */ if (aflag) { if(verbose) printf("%s%s", "ACCESS TIME = ", ctime(&sb.st_atime)); else printf("%ld", sb.st_atime); } if (cflag) { if(verbose) printf("%s%s", "CHANGE TIME = ", ctime(&sb.st_ctime)); else printf("%ld", sb.st_ctime); } if (mflag) { if(verbose) printf("%s%s", "MODIFY TIME = ", ctime(&sb.st_mtime)); else printf("%ld", sb.st_mtime); } printf("\n"); exit(0); } ------ EOF ------ ls -l ftimes.c