ftimes (file modification times) with human-readable format
john
john at sol1.UUCP
Sun Nov 10 08:48:56 AEST 1985
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 at 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 at rochester.{arpa,uucp}) 26th Sep 1985
**
** Added verbose -v option to output in human readable format
** John Korsmeyer (sol1!john) 9th Nov 1985
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
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
More information about the Comp.sources.unix
mailing list