From: ken@ssel.toshiba.co.jp (Iriuchijima Ken)
Newsgroups: fj.questions.unix
Subject: Re: How to compare mtime?
Date: 8 Jan 93 00:32:52 GMT
	<KANEKO.92Dec17211007@grain.rcais.tohoku.ac.jp>
	<KEN.92Dec21135321@pochi.ssel.toshiba.co.jp>
Reply-To: ken@ssel.toshiba.co.jp
Distribution: fj
Organization: Systems & Software Engineering Laboratory, TOSHIBA Corporation,
	JAPAN

$@F~FbEg(J@$@El<G$G$9!#(J

$@F~(J> bash$@$N(Jbuiltin command$@$N(Jtest$@$K$O(J
$@F~(J>           file1 -nt file2
$@F~(J>                True if file1 is newer (according to  modification
$@F~(J>                date) than file2.
$@F~(J>           file1 -ot file2
$@F~(J>                True if file1 is older than file2.
$@F~(J> $@$H$$$&Hf3S1i;;;R$,$"$C$F=EJu$7$F$$$^$9!#(J
$@F~(J> $@F1$8$3$H$r(Jbash$@$r(J$@;H$o$:$K(Jsh$@$G=q$/$H$7$?$i!"$I$&$7$?$i$$$$$G$7$g$&!)(J

$@$H$$$&<ALd$KBP$7!"(JNTT$@$N;0Bp$5$s!"ElKLBg$N6b;R$5$s(J$@!"02Bt!w$R$?$A$5$s$+(J
$@$i$N(Jfollow$@$HEDCf(J $@Ao(J(qtanaka@cs.uec.ac.jp )$@$5$s$+$i$N(Jreply$@$rD:$-$^$7$?!#(J

$@4JC1$K$^(J$@$H$a$k$H!"(J

1.	ls -1t$@$r;H$&(J

	if [ "`ls -1t file1 file2 | head -1`" = file1 ]; then

2.	find ... -newer$@$r;H$&(J

	if [ -n "`find file1 -newer file2 -print`" ] ; then ....
	file1$@$,(Jdirectory$@$N>l9g$O(J
	if [ `find $file1 -newer $file2 -print -prune -o -prune` ]; then

3.	$@C1BN$N(JGNU test$@$r;H$&(J

	bash-1.12$@$K$O(Jtest.c$@$,$"$j$^$9!#(Jfileutils$@$K$b$"$k$HJ9$$$?$N$G$9(J
	$@$,!"(Jfileutils-3.2, binutils-1.9$@$K$O8+Ev$?$i$J$$$h$&$G(J$@$9(J...?

$@$H$$$&;00F$K$J$j$^$9!#(J($@?H6a$J$H$3$m$+$i!V(Jperl$@$O!)!W$H$b8@$o$l$^$7$?$,!"(J
$@$I$&$;(Junix$@$KIU$$$F$3$J(J$@$$$b$N$r;H$&$J$i!"(JGNU test$@$NJ}$,Aa$$5$$,$7$^$9!#(J)

$@0z$C$+$+$k$H$9$l$P(J

    ls$@$G$O!"(Jfile1$@$H(Jfile2$@$NF|IU(J$@$,F1$8$H$-$O7k2L$,(Jfile$@L>$K0MB8$9$k!#(J
    find$@$O$d$d5mEa$N46$,$"$k!#(J
    GNU test$@$O(Jnot unix$@$G$"$k!#(J

$@$H(J$@$$$&$H$3$m$G$7$g$&$+!#8=<BE*$K$O!"(J`unix'$@$K$3$@$o$i$:$K(JGNU test$@$r;H$&(J
$@$N$,7k6I4JC1$=$&$G$9$M!#(J

#	$@$G$b(J$@!"0lHV$&$J$C$?$N$O(J1.$@$N(Jls$@$r;H$&J}K!$G$9!#$3$l$O9M$($F$b$$$^(J
#	$@$;$s$G$7$?!#(J


$@3'MM$I$&$b$"$j$,$H$&$4$6$$(J$@$^$7$?!#:G8e$K(JGNU test$@$K4X$9$kEDCf$5$s$N$*JV(J
$@;v$r0zMQ$7$F$*$-$^$9!#(J

$(BASH)/test.c$@$O!"(J

int
#if defined (STANDALONE)
main (margc, margv)
#else
test_command (margc, margv)
#endif /* STANDALONE */
     int margc;
     char **margv;
{

$@$J$N$G!"(J

cc -o [ -DSTANDALONE test.c

$@$9$l$P=jK>$N(J[$@$,=PMh$^$9!#(J

$@$3(J$@$l$N$*$+$2$G:#$G$O9,$;$KJk$i$7$F$$$^$9!#(J

$@IUO?(J--------------------system.h--------------------
#include <ctype.h>

#define whitespace(c)	isspace((c))
#define digit(c)	isdigit((c))
#define digit_value(c)	((c) - '0')	

#include <sys/stat.h>

#define S_ISREG(x) (S_IFREG & (x) ? 1 : 0)
#define S_ISDIR(x) (S_IFDIR & (x) ? 1 : 0)
#define S_ISCHR(x) (S_IFCHR & (x) ? 1 : 0)
#define S_ISBLK(x) (S_IFBLK & (x) ? 1 : 0)
$@IUO?$*$7$^$$(J----------------------------------------
--
	$@F~FbEg(J  $@7r(J				Tel. 044-548-5636
	ken@ssel.toshiba.co.jp			FAX  044-533-3593
	$@3t<02q<REl<G(J $@8&5f3+H/%;%s%?!<(J $@%7%9%F%`!&%=%U%H%&%'%"@8;:5;=Q(J$@8&5f=j(J