david@ukma.UUCP (David Herron, NPR Lover) (06/04/85)
Description: Find could really use a -bigger flag. The following context diff will describes how to add it to find. Syntax is "-bigger <file>". Which returns true for files which are bigger than the named file. Author: David Herron, ukma!david. Script started on Mon Jun 3 16:51:50 1985 ukma# rcsdiff -r1.1.1.1 -r1.1.1.4 -c find.c RCS file: RCS/find.c,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.4 diff -c -r1.1.1.1 -r1.1.1.4 *** /tmp/,RCSt1028957 Mon Jun 3 16:52:41 1985 --- /tmp/,RCSt2028957 Mon Jun 3 16:53:22 1985 *************** *** 1,5 #ifndef lint ! static char rcsid[] = "$Header: find.c,v 1.1.1.1 85/01/04 20:18:42 root Exp $"; #endif lint /* * $Locker: $ --- 1,5 ----- #ifndef lint ! static char rcsid[] = "$Header: find.c,v 1.1.1.4 85/06/03 16:41:03 root Exp $"; #endif lint /* * $Locker: $ *************** *** 4,9 /* * $Locker: $ * $Log: find.c,v $ * Revision 1.1.1.1 85/01/04 20:18:42 root * Branch for ukma changes * --- 4,23 ----- /* * $Locker: $ * $Log: find.c,v $ + * Revision 1.1.1.4 85/06/03 16:41:03 root + * Corrected a syntax error. + * ukma!david + * + * Revision 1.1.1.3 85/06/03 16:31:34 root + * Slight mistake. Forgot to define bigger() in e4(). + * ukma!david + * + * + * Revision 1.1.1.2 85/06/03 16:26:55 root + * Added command "-bigger file" which will find all the files bigger + * than the named file. + * -- ukma!david + * * Revision 1.1.1.1 85/01/04 20:18:42 root * Branch for ukma changes * *************** *** 42,47 int Wct = 2560; long Newer; struct stat Statb; --- 56,62 ----- int Wct = 2560; long Newer; + long Bigger; /* CHANGE ukma!david, for bigger() */ struct stat Statb; *************** *** 157,163 struct anode *e3() { /* parse parens and predicates */ int exeq(), ok(), glob(), mtime(), atime(), user(), group(), size(), perm(), links(), print(), ! type(), ino(), cpio(), newer(); struct anode *p1; int i; register char *a, *b, s; --- 172,178 ----- struct anode *e3() { /* parse parens and predicates */ int exeq(), ok(), glob(), mtime(), atime(), user(), group(), size(), perm(), links(), print(), ! type(), ino(), cpio(), newer(), bigger(); struct anode *p1; int i; register char *a, *b, s; *************** *** 248,253 } Newer = Statb.st_mtime; return mk(newer, (struct anode *)0, (struct anode *)0); } err: fprintf(stderr, "find: bad option < %s >\n", a); exit(1); --- 263,280 ----- } Newer = Statb.st_mtime; return mk(newer, (struct anode *)0, (struct anode *)0); + } else if (EQ(a, "-bigger")) { + /* + * CHANGE ukma!david -- Add in parsing for -bigger. + * Make everything look like -newer since it's the same + * kind of operation. + */ + if (stat(b, &Statb) < 0) { + fprintf(stderr, "find: cannot access < %s >\n", b); + exit(1); + } + Bigger = Statb.st_size; + return mk(bigger, (struct anode *)0, (struct anode *)0); } err: fprintf(stderr, "find: bad option < %s >\n", a); exit(1); *************** *** 442,447 newer() { return Statb.st_mtime > Newer; } /* support functions */ --- 469,478 ----- newer() { return Statb.st_mtime > Newer; + } + bigger() + { + return Statb.st_size > Bigger; } /* support functions */ ukma# script done on Mon Jun 3 16:58:23 1985
dave@lsuc.UUCP (David Sherman) (06/06/85)
Foo, grumble and feh! find(1) already has a "-size" option. If you want to compare size against another file, it's trivial to write a one-line awk script which feeds the right information to find(1). Dave Sherman The Law Society of Upper Canada Toronto -- { ihnp4!utzoo pesnta utcs hcr decvax!utcsri } !lsuc!dave
dce@hammer.UUCP (David Elliott) (06/07/85)
In article <663@lsuc.UUCP> dave@lsuc.UUCP (David Sherman) writes: >Foo, grumble and feh! find(1) already has a "-size" option. >If you want to compare size against another file, it's >trivial to write a one-line awk script which feeds the right >information to find(1). > >Dave Sherman >The Law Society of Upper Canada >Toronto >-- >{ ihnp4!utzoo pesnta utcs hcr decvax!utcsri } !lsuc!dave Put your money where your mouth is, Dave. The above note would imply that you can write an awk script that would generate a find command that looks something like this: find dir \( -size n -o -size n+1 -o -size n+2 ... \) How big can a file get? Now, take the following predicates: -size is to -bigger as -mtime is to -newer Your statement would imply that -newer can be replaced by an awk script to generate information for -mtime. Wrong! The missing quality here is granularity. If you read the manual page for find, you will see that -mtime is measured in days, whereas -newer is a true relative comparison. The -size primary is measured in blocks, whereas -bigger is again a true relative comparison. In other words, -bigger will find that a 4-byte file is bigger than a 3-byte file, whereas -size can not be so granular. Now, I agree that you could write -bigger as something like: find dir -print | print_if_bigger_than file (where 'print_if_bigger_than' is a program that prints the names of the files that are bigger), but this is very slow (eats machines for lunch and process slots for dinner) and doesn't give half of the capabilities that -bigger does. My only criticism of the -bigger modification is that it would be nice if its usage was: -bigger file (same as now) -bigger number where the latter would allow an exact number, and possibly K (*1024) and M (*(1024*1024)) as suffixes. Of course, THIS feature is mostly carried out by the -size option (though -size still isn't as granular). What we really need is a "find compiler". Do you run find on your machine every night? Do you know what it has to go through just to find out if a file is three days old and smaller than 10 blocks or owned by `fred' or setuid root? This can really chew up the ol' CPU cycles. David Elliott tektronix!tekecs!dce
allyn@sdcsvax.UUCP (Allyn Fratkin) (06/09/85)
In article <1315@hammer.UUCP>, dce@hammer.UUCP (David Elliott) writes: > In article <663@lsuc.UUCP> dave@lsuc.UUCP (David Sherman) writes: > >Foo, grumble and feh! find(1) already has a "-size" option. > > Put your money where your mouth is, Dave. The above note would > imply that you can write an awk script that would generate a > find command that looks something like this: > > find dir \( -size n -o -size n+1 -o -size n+2 ... \) > > How big can a file get? This kind of thing is already built into find. You say "find / -size +10 -print" to print the names of all files >= 10 blocks. The + makes it >=, not just ==. You can also say -10 to find files <= 10 blocks. You don't need to do all that or'ing. Besides, if you're worried about granularity, the real fix would be to make the -size option take a units parameter, not make -bigger take units. If -size takes units, then Dave's statement is correct even if you're worried about granularity. (How often have you wanted that much granularity?) To really do things right, if you really must have -bigger, you'll need a -smaller option too. Of course, -size does this already. I have to agree with dave; there's no point in having two (or three!) options that do the same thing when one does quite nicely. -- From the virtual mind of Allyn Fratkin allyn@UCSD.ARPA or UCSD EMU/Pascal Project {ucbvax, decvax, ihnp4} U.C. San Diego !sdcsvax!allyn "Generally you don't see that kind of behavior in a major appliance."
dixon@rtp47.UUCP (Wally Dixon) (06/11/85)
In article <924@sdcsvax.UUCP> allyn@sdcsvax.UUCP (Allyn Fratkin) writes: >This kind of thing is already built into find. You say >. . ."find / -size +10 -print" to print . . . >. . .make the -size option take a units parameter, . . . Absolutely. Note that System V release 2 Unix "find" allows you to append a "c" to the size, denoting characters (bytes). So you get "find / -size +10c..".
jerry@oliveb.UUCP (Jerry Aguirre) (06/13/85)
> find dir \( -size n -o -size n+1 -o -size n+2 ... \) > > How big can a file get? > > David Elliott > tektronix!tekecs!dce This is not really necessary, all the numeric arguments can have an optional plus or minus sign in front of them. Thus "-size +n" is sufficent. I agree with your comments about the granularity of find on time and size arguments. It is silly to restrict the user to increments of 86,400 times the basic unit being compared. (That's one day in seconds.) If the designer wanted to make it easier to specify units more useful than a second or a byte then using a afix multipler such as s, h, d, m, or y to indicate seconds, hours, days, months, or years would have been much more flexable. The same scheme could be used for sizes using c, k, b, or w (as in the dd command). Perhaps an added option to find that would allow afixes to numeric arguments but retain the default units of days and blocks could solve this problem. Jerry Aguirre @ Olivetti ATC {hplabs|fortune|idi|ihnp4|tolerant|allegra|tymix}!oliveb!jerry
dave@lsuc.UUCP (David Sherman) (06/14/85)
In article <1315@hammer.UUCP> dce@hammer.UUCP (David Elliott) writes: ||In article <663@lsuc.UUCP> dave@lsuc.UUCP (David Sherman) writes: ||>Foo, grumble and feh! find(1) already has a "-size" option. ||>If you want to compare size against another file, it's ||>trivial to write a one-line awk script which feeds the right ||>information to find(1). ||> ||>Dave Sherman ||Put your money where your mouth is, Dave. The above note would ||imply that you can write an awk script that would generate a ||find command that looks something like this: || || find dir \( -size n -o -size n+1 -o -size n+2 ... \) No, I don't need an awk script for that, I type find dir -size +n ... The awk script is to compare size against another file - for that you'd run ls and use awk to extract the size to compare against. Dave Sherman -- { ihnp4!utzoo pesnta utcs hcr decvax!utcsri } !lsuc!dave