Date: Tue, 4 Sep 2001 14:45:11 +0200 (CEST) From: Nils M Holm <nmh@t3x.org> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/30309: New FIND(1) option Message-ID: <Pine.BSF.4.21.0109041442430.1819-100000@Oxygen2.UUCP>
next in thread | raw e-mail | index | archive | help
>Number: 30309 >Category: bin >Synopsis: New FIND(1) option >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Tue Sep 04 05:50:01 PDT 2001 >Closed-Date: >Last-Modified: >Originator: Nils M Holm >Release: FreeBSD 4.2-RELEASE i386 >Organization: >Environment: FreeBSD 4.2-RELEASE >Description: I have added the -nt (newer than) option to FIND(1) which allows to search for files with at least/at most a given age. For example, find . -nt 5h30m will list files with an age of at least 5 hours and 30 minutes. I use this option for cleaning up spool directories. Man pages are updated. >How-To-Repeat: >Fix: diff -u /usr/src/usr.bin/find.old/extern.h /usr/src/usr.bin/find/extern.h --- /usr/src/usr.bin/find.old/extern.h Tue Sep 4 14:07:04 2001 +++ /usr/src/usr.bin/find/extern.h Tue Sep 4 14:09:51 2001 @@ -69,6 +69,7 @@ PLAN *c_newer __P((char *)); PLAN *c_nogroup __P((void)); PLAN *c_nouser __P((void)); +PLAN *c_nt __P((char *)); PLAN *c_path __P((char *)); PLAN *c_perm __P((char *)); PLAN *c_print __P((void)); diff -u /usr/src/usr.bin/find.old/find.1 /usr/src/usr.bin/find/find.1 --- /usr/src/usr.bin/find.old/find.1 Tue Sep 4 14:07:04 2001 +++ /usr/src/usr.bin/find/find.1 Tue Sep 4 14:32:23 2001 @@ -291,6 +291,12 @@ True if the file belongs to an unknown user. .It Ic -nogroup True if the file belongs to an unknown group. +.It Ic -nt Ar difference +True if the current file has a more recent last modification time than +the current time minus the specified difference (the file is newer than +the given amount of time). Time values may have suffixes: s=seconds, +m=minutes, h=hours, D=days, W=weeks, M=months (30D), Y=years (365D). +Suffixes may be mixed: -nt 5h30m. .It Ic -path Ar pattern True if the pathname being examined matches .Ar pattern . diff -u /usr/src/usr.bin/find.old/find.h /usr/src/usr.bin/find/find.h --- /usr/src/usr.bin/find.old/find.h Tue Sep 4 14:07:04 2001 +++ /usr/src/usr.bin/find/find.h Tue Sep 4 14:08:41 2001 @@ -44,8 +44,8 @@ N_EXEC, N_EXECDIR, N_EXPR, N_FLAGS, N_FOLLOW, N_FSTYPE, N_GROUP, N_INUM, N_LINKS, N_LS, N_MMIN, N_MTIME, N_NAME, - N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PATH, - N_PERM, N_PRINT, N_PRUNE, N_SIZE, N_TYPE, N_USER, N_XDEV, + N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_NT, N_OK, N_OPENPAREN, N_OR, + N_PATH, N_PERM, N_PRINT, N_PRUNE, N_SIZE, N_TYPE, N_USER, N_XDEV, N_PRINT0, N_DELETE, N_MAXDEPTH, N_MINDEPTH }; diff -u /usr/src/usr.bin/find.old/function.c /usr/src/usr.bin/find/function.c --- /usr/src/usr.bin/find.old/function.c Tue Sep 4 14:07:04 2001 +++ /usr/src/usr.bin/find/function.c Tue Sep 4 14:26:29 2001 @@ -59,6 +59,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <ctype.h> #include "find.h" @@ -940,6 +941,75 @@ ftsoptions &= ~FTS_NOSTAT; return (palloc(N_NOUSER, f_nouser)); +} + +/* + * -nt diff functions -- + * + * True if the different between the current time and the file + * modification time is less than the specified difference. + */ +int +f_nt(plan, entry) + PLAN *plan; + FTSENT *entry; +{ + extern time_t now; + + return (entry->fts_statp->st_mtime > now - plan->t_data); +} + +PLAN * +c_nt(difftime) + char *difftime; +{ + PLAN *new; + time_t secs, a; + char *s; + + ftsoptions &= ~FTS_NOSTAT; + + secs = 0L; + a = 0L; + for (s = difftime; *s; s++) { + if (isdigit(*s)) { + a = a*10 + *s-'0'; + } + else if (*s == 's') { /* seconds */ + secs += a; + a = 0L; + } + else if (*s == 'm') { /* minutes */ + secs += a*60L; + a = 0L; + } + else if (*s == 'h') { /* hours */ + secs += a*3600L; + a = 0L; + } + else if (*s == 'D') { /* days */ + secs += a*86400L; + a = 0L; + } + else if (*s == 'W') { /* weeks */ + secs += a*604800L; + a = 0L; + } + else if (*s == 'M') { /* months (d*30)*/ + secs += a*2592000L; + a = 0L; + } + else if (*s == 'Y') { /* years (d*365)*/ + secs += a*31536000L; + a = 0L; + } + else { + errx(1, "-nt: bad difference: %s", difftime); + } + } + new = palloc(N_NT, f_nt); + new->t_data = secs; + return (new); } /* diff -u /usr/src/usr.bin/find.old/option.c /usr/src/usr.bin/find/option.c --- /usr/src/usr.bin/find.old/option.c Tue Sep 4 14:07:04 2001 +++ /usr/src/usr.bin/find/option.c Tue Sep 4 14:09:28 2001 @@ -92,6 +92,7 @@ { "-newer", N_NEWER, c_newer, O_ARGV }, { "-nogroup", N_NOGROUP, c_nogroup, O_ZERO }, { "-nouser", N_NOUSER, c_nouser, O_ZERO }, + { "-nt", N_NT, c_nt , O_ARGV }, { "-o", N_OR, c_or, O_ZERO }, { "-ok", N_OK, c_exec, O_ARGVP }, { "-or", N_OR, c_or, O_ZERO }, >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0109041442430.1819-100000>