rcsmith@anagld.UUCP (Ray Smith) (06/08/88)
In article <344@ajpo.sei.cmu.edu> jrkelly@ajpo.sei.cmu.edu (John Kelly) writes: > ... The only other command I know of that compares modification times >is "find" with the "-newer file" option, which lists files that are newer >than the specified file. But unless one can force the specified file to >have the desired cutoff modification time, this option does not help. Try the "find" command with either the "-mtime" or "-atime" options for modified time or access time. An example of finding all files modified with in the last week follows: find . -mtime -7 -a ! -type d -print ^^^^^^^^^ We don't want any directories do we?? Cheers, Ray -- Ray Smith | USnail: Suite 200, 9891 Broken Land Pky, Columbia, MD 21046 Analytics, Inc. | GEnie : rcsmith (301) 381-4300 | CIS : 72000,1111 | Net : ...!uunet!mimsy!aplcen!anagld!rcsmith =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= "The trouble with doing something right the first time is that nobody appreciates how difficult it was." -Walt West =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
lew@gsg.UUCP (Paul Lew) (06/08/88)
> Has anyone implemented any of the following for Unix: > > 2. a program to force a specified modification time upon a specified file? comp.sources.misc/8707/33: settime (change the access and modification dates of files) > 3. a program to compare two dates/times and return an appropriate status? com.sources.misc/8708/12: changed (output file names that are modified after mmddyy) We use it here and find it very useful. It works on date only, not time. usage: changed mmddyy dir... alias today "changed `dnt --1 -f=mmddyy`" $ today /usr/spool/news where dnt is my version of date and time, the --1 option give me yesterday's date so changed will work properly. One bug: you can not do: "today ." if you have >1 level of subdirectories. -- Paul Lew {oliveb,harvard,decvax}!gsg!lew (UUCP) General Systems Group, 5 Manor Parkway, Salem, NH 03079 (603) 893-1000
root@conexch.UUCP (Larry Dighera) (06/08/88)
In article <10981@cgl.ucsf.EDU> seibel@hegel.mmwb.ucsf.edu.UUCP (George Seibel) writes: >In article <344@ajpo.sei.cmu.edu> jrkelly@ajpo.sei.cmu.edu (John Kelly) writes: >> >>In VMS and TOPS-20, the directory listing commands have a /since option that >>allows one to easily obtain a list of files modified since a specified time >>and date. [...] > >I also find this a very useful thing to have. After the e/f/grep mess is >cleaned up, maybe someone will do some work on ls. In the meanwhile, I >find the following alias very helpful: >alias lst5 ls -lst | head -6 >This shows you the 5 newest files, plus the total space used in the directory. I didn't see the original article that spawned this discussion, but it is a simple matter to get a listing of the files that have been changed within n days. Try this: find . -ctime -n -exec ls -l {} \; Where n is the number of days. Use -n to see all files newer than n-days old, and +n to see all files older n-days old. You can also use all the other useful options to find like -type, -user, -size, ... There is a problem with this approach however, there's no way that I am aware of to prevent find from descending the directory tree. There's yet another option that would be useful for find. Best Regards, Larry Dighera -- USPS: The Consultants' Exchange, PO Box 12100, Santa Ana, CA 92712 TELE: (714) 842-6348: BBS (N81); (714) 842-5851: Xenix guest account (E71) UUCP: conexch Any ACU 2400 17148425851 ogin:-""-ogin:-""-ogin: nuucp UUCP: ...!uunet!turnkey!conexch!root || ...!trwrb!ucla-an!conexch!root
les@chinet.UUCP (Leslie Mikesell) (06/10/88)
In article <355@conexch.UUCP> root@conexch.UUCP (Larry Dighera) writes: >simple matter to get a listing of the files that have been changed within >n days. Try this: > > find . -ctime -n -exec ls -l {} \; I would like to have a listing that shows only directory names (without showing subdirectories) with the date of the last change to any non-directory file contained in that tree. Comparing this to a similar listing of archive files would show which ones need to be updated. The date of a directory itself is pretty useless for this purpose, since compressing files, compiling, deleting *.o files, etc. will affect the dir date even though no real changes have happened. I have almost resorted to running zoo on all the directories where I am not actively working just to get this effect... Can it be done with any of the usual tools? Hmm.. might be a good job for perl when the version with filename globbing is released. Les Mikesell
leo@philmds.UUCP (Leo de Wit) (06/12/88)
In article <344@ajpo.sei.cmu.edu> jrkelly@ajpo.sei.cmu.edu (John Kelly) writes: >In VMS and TOPS-20, the directory listing commands have a /since option that [stuff deleted] >Has anyone implemented any of the following for Unix: > > 1. a directory listing command with a -since option? > 2. a program to force a specified modification time upon a specified file? > 3. a program to compare two dates/times and return an appropriate status? > >where the dates/times are given in string form, as in the output of "date" and >"ls"? 1. Is easy. You were on the right way. Use 'find' with the '-mtime' option. In this way you can also have your /before qualifier (yes, I'm also deemed to use Very Mediocrate System now and then 8-). You even have a /at qualifier! Example: ls -l `find . -mtime -7 -print` # files modified since last week (could also use find with -exec ls -l {}, but that's much slower). Note that find does recursively descend the directory structure. There is also a -atime option to match on access time if you're interested. 2. That's also easy. I've created a file older than any computer and one in the next century doing that. You can use the utimes() system call; it is in the Ultrix system. 3. There's a standard Un*x program that compares dates/times (of files that is); it is called make. You can use make for much more than only software generation. Use you imagination. If you want the time(s) of a file, use stat() (or fstat()). You can of course use find to compare dates/times of files: find . -name secondname -newer firstfile -print prints secondname if it is new than firstfile. The usefulness of string form dates/times I don't quite see, being perfectly happy with -mtime -7 and the like. Leo.
scs@athena.mit.edu (Steve Summit) (06/17/88)
Two additional points: 1. Beware that find -newer is slightly buggy; the implementation is simpleminded and can only handle a single -newer. Therefore, something like find -newer oldfile ! -newer newfile -print (which wasn't implied by the original question, but which I've occasionally wanted to use) doesn't work. (It ought to print the names of those files newer than oldfile but not newer than newfile, i.e. a range.) I've fixed this; I don't remember if I posted the fixes (or indeed even the bug). 2. There are (probably nonstandard) versions of test that can do test file1 -nt file2 and test file1 -ot file2 ("newer than" and "older than"). Steve Summit scs@adam.pika.mit.edu
leo@philmds.UUCP (Leo de Wit) (06/17/88)
In article <355@conexch.UUCP> root@conexch.UUCP (Larry Dighera) writes: >In article <10981@cgl.ucsf.EDU> seibel@hegel.mmwb.ucsf.edu.UUCP (George Seibel) writes: [lines deleted]... simple matter to get a listing of the files that have been changed within n days. Try this: find . -ctime -n -exec ls -l {} \; Where n is the number of days. Use -n to see all files newer than n-days old, and +n to see all files older n-days old. You can also use all the other useful options to find like -type, -user, -size, ... There is a problem with this approach however, there's no way that I am aware of to prevent find from descending the directory tree. There's yet another option that would be useful for find. If you reverse the find and the ls, you get a much faster one: ls -l `find . -ctime -n -print` Only one ls needed for all the files (the former solution fires up an ls for each file that satisfies the condition); you could even use it to exclude subdirectories, although find will do recursion: ls -l `find . -ctime -n -print|sed '/\/.*\//d'` i.e. sed removes lines containing two or more /'s. Not to be recommended for deep nesting! Leo.