[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to grep without changing timestamps?



You need to make sure that something calls utime() to reset the filestamps.  You can't reset the ctime (inode change time), but the atime (inode access time) and the mtime (inode timestamp) are changable.

Here is a simple example Perl script that works a little like grep:
--
#!/usr/bin/perl

use strict;

my ($regexp);

$regexp = shift @ARGV;

for my $filename (@ARGV) {
        my @stat = stat $filename or do {
                print STDERR "stat of $filename failed; $!\n";
                next;
        };

        open FILE, "<$filename" or do {
                print STDERR ("open of $filename for reading failed; "
                              ."$!\n");
                next;
        };

        while (<FILE>) {
                m/$regexp/ && print "$filename: $_";
        }

        close FILE;

        utime @stat[8,9], $filename or
                print STDERR "utime call of $filename failed; $!\n";
}
--
Cheers,
Sam.

On Sun, 31 Dec 2000 14:04:57 -0500
Maciej Kalisiak <mac@cs.toronto.edu> wrote:

> Hello all,
> 
> Is it possible to grep a ton of files without modifying their date/timestamps?
> Currently if I use grep, it changes the access time of all files touched,
> which causes mutt to lose track of the folders which have new mail (I guess it
> looks at the timestamp last modified and last accessed to figure this out).
> Occasionally I do want to include the mail folders in my greps, so bypassing
> the "mail" directory is not a solution.
> 
> -- 
> Maciej Kalisiak		mac@dgp.toronto.edu	www.dgp.toronto.edu/~mac
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org 
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
> 
> 
> 


--
Sam Vilain, sam@vilain.net        WWW: http://sam.vilain.net/
GPG public key: http://sam.vilain.net/sam.asc



Reply to: