linux-admin.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Samuel <samuel@bcgreen.com>
To: "César Soler" <csoler@euskalnet.net>, linux-admin@vger.kernel.org
Subject: Re: test the file date
Date: Tue, 10 Jun 2003 14:03:14 -0700	[thread overview]
Message-ID: <3EE64792.5070704@bcgreen.com> (raw)
In-Reply-To: <15497219844.20030610115010@euskalnet.net>

César Soler wrote:
> Hi,
> 
> 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 only
> need two files:
> 
> $PATH/file
> $PATH/backup/file
> $PATH/export/file
> 
> if I find from "$PATH" all files, with name "file" and "-mtime -1", at
> least three files appear, but I only need two of them.
> 
> Is there any shell tool to check the date? something likes "test" or
> "file", that is able to check the modified time....
> 
> any clue is welcome!
> Thks in advance
> 

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=`date +%y%m%d`
testfile=`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=$ARGV[0];
( $sec, $min,$hour,$mday,$mon,$year ) = 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=GMT  	# Greenwich Mean Time
	or
   export TZ=EST5EDT	# Eastern Standard / daylight time.
   sxport TZ=MST7	# 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

-- 
Stephen Samuel +1(604)876-0426                samuel@bcgreen.com
		   http://www.bcgreen.com/~samuel/
Powerful committed communication, reaching through fear, uncertainty and
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

  parent reply	other threads:[~2003-06-10 21:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-10  9:50 test the file date César Soler
2003-06-10  9:49 ` Joakim Ryden
2003-06-10 10:10   ` Re[2]: " César Soler
2003-06-10 15:23 ` Glynn Clements
2003-06-10 21:03 ` Stephen Samuel [this message]
2003-06-10 21:11   ` Mr. James W. Laferriere
2003-06-10 23:03     ` Stephen Samuel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3EE64792.5070704@bcgreen.com \
    --to=samuel@bcgreen.com \
    --cc=csoler@euskalnet.net \
    --cc=linux-admin@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).