add -r option, allowing -exec/-ok to do relative traversal
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 23 Oct 1990 01:52:29 +0000 (17:52 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 23 Oct 1990 01:52:29 +0000 (17:52 -0800)
SCCS-vsn: usr.bin/find/find.1 6.16
SCCS-vsn: usr.bin/find/function.c 5.9
SCCS-vsn: usr.bin/find/misc.c 5.3
SCCS-vsn: usr.bin/find/main.c 5.3

usr/src/usr.bin/find/find.1
usr/src/usr.bin/find/function.c
usr/src/usr.bin/find/main.c
usr/src/usr.bin/find/misc.c

index 91f557e..7f08e69 100644 (file)
@@ -3,7 +3,7 @@
 .\"
 .\" %sccs.include.redist.man%
 .\"
 .\"
 .\" %sccs.include.redist.man%
 .\"
-.\"     @(#)find.1     6.15 (Berkeley) %G%
+.\"     @(#)find.1     6.16 (Berkeley) %G%
 .\"
 .Dd 
 .Dt FIND 1
 .\"
 .Dd 
 .Dt FIND 1
 .Nd walk a file hierarchy
 .Sh SYNOPSIS
 .Nm find
 .Nd walk a file hierarchy
 .Sh SYNOPSIS
 .Nm find
-.Op Fl dsx
+.Op Fl drsx
 .Op Ar path
 .Ar expression
 .Nm find
 .Op Ar path
 .Ar expression
 .Nm find
-.Op Fl dsx
+.Op Fl drsx
 .Op Fl f Ar path
 .Ar expression
 .Sh DESCRIPTION
 .Op Fl f Ar path
 .Ar expression
 .Sh DESCRIPTION
@@ -35,7 +35,9 @@ The options are as follows:
 .Tp Fl d
 The
 .Fl d
 .Tp Fl d
 The
 .Fl d
-option causes find to perform a depth\-first traversal, i.e. directories
+option causes
+.Nm find
+to perform a depth\-first traversal, i.e. directories
 are visited in post\-order and all entries in a directory will be acted
 on before the directory itself.
 By default,
 are visited in post\-order and all entries in a directory will be acted
 on before the directory itself.
 By default,
@@ -54,6 +56,25 @@ If no
 .Fl f
 option is specified, the first operand after the options is
 expected to be the file hierarchy to be traversed.
 .Fl f
 option is specified, the first operand after the options is
 expected to be the file hierarchy to be traversed.
+.Tp Fl r
+The
+.Fl r
+option permits
+.Nm find
+to execute the utility specified for the
+.Ic exec
+and
+.Ic ok
+primaries from other than the directory where
+.Nm find
+was executed.
+.Nm Find
+may then change directories during the file hierarchy walk, meaning
+that
+.Nm find
+can traverse hierarchies with path names longer than those directly
+resolvable by the kernel.
+This usually results in a performance improvement as well.
 .Tp Fl s
 The
 .Fl s
 .Tp Fl s
 The
 .Fl s
index 80fc274..b7f2cf9 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)function.c 5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)function.c 5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -199,7 +199,7 @@ f_exec(plan, entry)
        for (cnt = 0; plan->e_argv[cnt]; ++cnt)
                if (plan->e_len[cnt])
                        find_subst(plan->e_orig[cnt], &plan->e_argv[cnt],
        for (cnt = 0; plan->e_argv[cnt]; ++cnt)
                if (plan->e_len[cnt])
                        find_subst(plan->e_orig[cnt], &plan->e_argv[cnt],
-                           entry->fts_path, plan->e_len[cnt]);
+                           entry->fts_accpath, plan->e_len[cnt]);
 
        if (plan->flags && !find_queryuser(plan->e_argv))
                return(0);
 
        if (plan->flags && !find_queryuser(plan->e_argv))
                return(0);
@@ -232,11 +232,13 @@ c_exec(argvp, isok)
        char ***argvp;
        int isok;
 {
        char ***argvp;
        int isok;
 {
+       extern int relative;
        PLAN *new;                      /* node returned */
        register int cnt;
        register char **argv, **ap, *p;
 
        PLAN *new;                      /* node returned */
        register int cnt;
        register char **argv, **ap, *p;
 
-       ftsoptions |= FTS_NOCHDIR;
+       if (!relative)
+               ftsoptions |= FTS_NOCHDIR;
        output_specified = 1;
     
        NEW(T_EXEC, f_exec);
        output_specified = 1;
     
        NEW(T_EXEC, f_exec);
index a18cd49..d93aab1 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -15,6 +15,8 @@ static char sccsid[] = "@(#)main.c    5.2 (Berkeley) %G%";
 #include <fts.h>
 #include "find.h"
 
 #include <fts.h>
 #include "find.h"
 
+int relative;
+
 newsyntax(argc, argvp)
        int argc;
        char ***argvp;
 newsyntax(argc, argvp)
        int argc;
        char ***argvp;
@@ -25,7 +27,7 @@ newsyntax(argc, argvp)
        char **argv, **cur;
 
        cur = argv = *argvp;
        char **argv, **cur;
 
        cur = argv = *argvp;
-       while ((ch = getopt(argc, argv, "df:sx")) != EOF)
+       while ((ch = getopt(argc, argv, "df:rsx")) != EOF)
                switch(ch) {
                case 'd':
                        depth = 1;
                switch(ch) {
                case 'd':
                        depth = 1;
@@ -33,6 +35,9 @@ newsyntax(argc, argvp)
                case 'f':
                        *cur++ = optarg;
                        break;
                case 'f':
                        *cur++ = optarg;
                        break;
+               case 'r':
+                       relative = 1;
+                       break;
                case 's':
                        ftsoptions &= ~FTS_PHYSICAL;
                        ftsoptions |= FTS_LOGICAL;
                case 's':
                        ftsoptions &= ~FTS_PHYSICAL;
                        ftsoptions |= FTS_LOGICAL;
index d697d16..c3b3039 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)misc.c     5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)misc.c     5.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -101,6 +101,6 @@ usage()
                (void)fprintf(stderr, "usage: find path-list expression\n");
        else
                (void)fprintf(stderr,
                (void)fprintf(stderr, "usage: find path-list expression\n");
        else
                (void)fprintf(stderr,
-                   "usage: find [-dsx] -f path ... expression\n");
+                   "usage: find [-drsx] -f path ... expression\n");
        exit(1);
 }
        exit(1);
 }