englund@tramp.Colorado.EDU (ENGLUND TODD CHARLES) (10/30/90)
Does anyone know how to change the last date a file was altered? Even if one doesn't happen to be a super-user? Thanks -Todd
n8743196@unicorn.wwu.edu (Jeff Wandling) (10/31/90)
englund@tramp.Colorado.EDU (ENGLUND TODD CHARLES) writes: > Does anyone know how to change the last date a file was altered? Even >if one doesn't happen to be a super-user? >Thanks >-Todd % touch filename This will just update the last time the file was modified. -- jeff wandling internet: n8743196@unicorn.cs.wwu.edu cs ugrad @ western washington university illegitimi non carborundum
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (10/31/90)
In article <28928@boulder.Colorado.EDU> englund@tramp.Colorado.EDU (ENGLUND TODD CHARLES) writes:
:
: Does anyone know how to change the last date a file was altered? Even
: if one doesn't happen to be a super-user?
perl -e '$DAYS = 24*60*60; utime(time, time - 30 * $DAYS, @ARGV)' file1 file2...
will change the mod time of all listed files to 30 days ago. (And changes
the last access to the current time.)
You do, of course, have to be the owner of the files or superuser.
Larry Wall
lwall@jpl-devvax.jpl.nasa.gov
engbert@cs.vu.nl (=Engbert Gerrit IJff) (10/31/90)
In article <28928@boulder.Colorado.EDU>, englund@tramp.Colorado.EDU (ENGLUND TODD CHARLES) writes: > > Does anyone know how to change the last date a file was altered? Even > if one doesn't happen to be a super-user? > > Thanks > -Todd I can hardly imagine you didn't see touch(1) in the FM. Maybe you can be a little more explicit? Regards Bert
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (10/31/90)
In article <8096@star.cs.vu.nl> engbert@cs.vu.nl (=Engbert Gerrit IJff) writes: : In article <28928@boulder.Colorado.EDU>, : englund@tramp.Colorado.EDU (ENGLUND TODD CHARLES) writes: : > : > Does anyone know how to change the last date a file was altered? Even : > if one doesn't happen to be a super-user? : > : > Thanks : > -Todd : I can hardly imagine you didn't see touch(1) in the FM. : Maybe you can be a little more explicit? A quick telnet to tramp.colorado.edu reveals that it is running DYNIX, a BSD clone. As such, it's unlikely to have a touch command that can set the file's modification time to anything but the current time. Please, folks, don't assume everyone's system works just like yours. [ OK, then how come you assume everyone has installed Perl? ] Oh, shush! Larry Wall lwall@jpl-devvax.jpl.nasa.gov
brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (10/31/90)
In article <28928@boulder.Colorado.EDU> englund@tramp.Colorado.EDU (ENGLUND TODD CHARLES) writes: > Does anyone know how to change the last date a file was altered? Even > if one doesn't happen to be a super-user? Use the utimes() system call. You can never change the ctime to anything but the current time, except by changing the system time or writing the raw disk. Note that any uses of the atime/mtime for security should also check the ctime. ---Dan
pierreg@siegfried.vlsi.polymtl.ca (Pierre Girard) (11/21/90)
Here is a small C program that can help you do this. ---- CUT HERE --- /* This program can change the date and time of a file using the current time a a reference. Arguments : [-d days] [-h hour] [-m minutes] -[s seconds] [file1][file2]... Defaults values give the same results as touch Programmer : Pierre Girard November 1990 */ #include <utime.h> #include <sys/time.h> #define DAY (24*HOUR) #define HOUR (60*MIN) #define MIN (60*SEC) #define SEC (1) main(argc,argv) int argc; char **argv; { struct utimbuf times; time_t tloc; int i; int deltad=0, deltah=0, deltam=0, deltas=0; for(i=1;i<argc;i++) { if(!strcmp("-d",argv[i])) { ++i; deltad=atoi(argv[i]); } if(!strcmp("-h",argv[i])) { ++i; deltah=atoi(argv[i]); } if(!strcmp("-m",argv[i])) { ++i; deltam=atoi(argv[i]); } if(!strcmp("-s",argv[i])) { ++i; deltas=atoi(argv[i]); } } times.actime= time(&tloc); /* acces time */ times.modtime= time(&tloc) + deltad* DAY+deltah*HOUR+deltam*MIN+deltas; /* acces time */ for (i=1;i<argc;i++) utime(argv[i],×); } -- ___ ___ ___ ___ ___ ___ ___ / /__ /__/ /__/ /__ /__/ /__ /__ /__ / \ /__/ /___ / \ /___ Pierre Girard, Student in computer ingeneering, Ecole Polytechnique de Montreal, Quebec, Canada. pierreg@info.polymtl.ca