From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Samuel Subject: Re: test the file date Date: Tue, 10 Jun 2003 14:03:14 -0700 Sender: linux-admin-owner@vger.kernel.org Message-ID: <3EE64792.5070704@bcgreen.com> References: <15497219844.20030610115010@euskalnet.net> Mime-Version: 1.0 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: <15497219844.20030610115010@euskalnet.net> List-Id: Content-Type: text/plain; charset="iso-8859-1"; To: =?ISO-8859-1?Q?C=E9sar_Soler?= , linux-admin@vger.kernel.org C=E9sar Soler wrote: > Hi, >=20 > I would like to process a pair of files if they were modified in the > previous day. I have tried with "find", but the problem is that I onl= y > need two files: >=20 > $PATH/file > $PATH/backup/file > $PATH/export/file >=20 > if I find from "$PATH" all files, with name "file" and "-mtime -1", a= t > least three files appear, but I only need two of them. >=20 > Is there any shell tool to check the date? something likes "test" or > "file", that is able to check the modified time.... >=20 > any clue is welcome! > Thks in advance >=20 it's kinda hard to figure what you mean by 'test the date'... If you're looking for something that was made 'today', then you could do something like: thismorn=3D`date +%y%m%d` testfile=3D`mktmp /tmp/today.XXXXXX` touch -t "$thismorn"0000 $testfile find /some/path -newer $testfile -print rm $testfile Note that it takes a bit more magic to properly come up with a date string for yesterday... I can think of a perl script that could do it: ----------------------- #!/usr/bin/perl die "Usage: $0 number_of_days_ago\n" $days_ago=3D$ARGV[0]; ( $sec, $min,$hour,$mday,$mon,$year ) =3D localtime(time-$days_ago*3600= *24); printf "%02d%02d%02d\n", $year % 100 , $mon+1, $mday; ----------------------- (in perl, the year is years since 1900, so 2003 comes out as 103. Months are based on january being month 0, so 1 must be added to the month. I take $year mod 100 rather than blindly subtracting 100 ) note that all of these presume that you calculate the date based on your local time. If you want it based on some other time, then you should set (and export) TZ to be the appropriate timezone. eg: export TZ=3DGMT # Greenwich Mean Time or export TZ=3DEST5EDT # Eastern Standard / daylight time. sxport TZ=3DMST7 # Mountain Standard time (no daylight savings) If you put the perlscript in the file saysago (somewhere in your path), then the usage would be: touch `daysago 1`0000 `mktemp /tmp/ er, um, then again, you could just read the man page for find, and notice that you've got a -daystart option, which says to count file age starting at midnight, tonight rather than the current time. (time zones still apply) (Note: this solution -- while the quickest and easiest may not be portable to commercial (non-GNU) versions of the UNIX find(1) command) In other words... find /some/path -daystart -mtime -1 -print --=20 Stephen Samuel +1(604)876-0426 samuel@bcgreen.com http://www.bcgreen.com/~samuel/ Powerful committed communication, reaching through fear, uncertainty an= d doubt to touch the jewel within each person and bring it to life. - To unsubscribe from this list: send the line "unsubscribe linux-admin" = in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html