summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authoreik <eik@FreeBSD.org>2004-05-28 17:17:15 +0000
committereik <eik@FreeBSD.org>2004-05-28 17:17:15 +0000
commit67b0af2d89cbb9ad02ca489ff6320ffe6bf878d5 (patch)
treede2701bbe39f57e4860326018916a82714254cdb /usr.bin
parent577b8571b9834b90908480fd24b3383ed54f7b4c (diff)
downloadFreeBSD-src-67b0af2d89cbb9ad02ca489ff6320ffe6bf878d5.zip
FreeBSD-src-67b0af2d89cbb9ad02ca489ff6320ffe6bf878d5.tar.gz
- introduce a new primary `-depth n', which tests whether
the depth of the current file relative to the starting point of the traversal is n. The usual +/- modifiers to the argument apply. - while I'm here, fix -maxdepth in the case of a depth-first traversal Print the top ten maintainers of python module ports (works with p5-* too): find /usr/ports -depth 2 \! -name 'py-*' -prune -o \ -depth 3 -name Makefile -execdir make -VMAINTAINER \; \ | sort | uniq -c | sort -nr | head PR: 66667 Reviewed by: ru, joerg Approved by: joerg MFC after: 2 weeks
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/find/extern.h1
-rw-r--r--usr.bin/find/find.148
-rw-r--r--usr.bin/find/find.c11
-rw-r--r--usr.bin/find/find.h3
-rw-r--r--usr.bin/find/function.c54
-rw-r--r--usr.bin/find/option.c2
6 files changed, 91 insertions, 28 deletions
diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h
index 67a8e3b..0e01f82 100644
--- a/usr.bin/find/extern.h
+++ b/usr.bin/find/extern.h
@@ -87,6 +87,7 @@ exec_f f_acl;
exec_f f_always_true;
exec_f f_closeparen;
exec_f f_delete;
+exec_f f_depth;
exec_f f_empty;
exec_f f_exec;
exec_f f_expr;
diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1
index 10cf157..ec0933f 100644
--- a/usr.bin/find/find.1
+++ b/usr.bin/find/find.1
@@ -34,7 +34,7 @@
.\" @(#)find.1 8.7 (Berkeley) 5/9/95
.\" $FreeBSD$
.\"
-.Dd May 16, 2004
+.Dd May 28, 2004
.Dt FIND 1
.Os
.Sh NAME
@@ -133,9 +133,18 @@ Note, the default is
.Em not
a breadth-first traversal.
.Pp
-This option is equivalent to the deprecated
+This option is equivalent to the
.Ic -depth
-primary.
+primary of
+.St -p1003.1-2001 .
+.Fl d
+can be useful when
+.Nm
+is used with
+.Xr cpio 1
+to process files that are contained in directories with unusual permissions.
+It ensures that you have write permission while you are placing files in a
+directory, then sets the directory's permissions as the last thing.
.It Fl f
Specify a file hierarchy for
.Nm
@@ -264,14 +273,10 @@ Always true;
same as the
.Fl d
option.
-.Ic -depth
-can be useful when
-.Nm
-is used with
-.Xr cpio 1
-to process files that are contained in directories with unusual permissions.
-It ensures that you have write permission while you are placing files in a
-directory, then sets the directory's permissions as the last thing.
+.It Ic -depth Ar n
+True if the depth of the file relative to the starting point of the traversal
+is
+.Ar n .
.It Ic -empty
True if the current file or directory is empty.
.It Ic -exec Ar utility Oo Ar argument ... Oc Li \&;
@@ -765,6 +770,17 @@ recent than the current time minus one minute.
Use the
.Xr echo 1
command to print out a list of all the files.
+.It Li "find -L /usr/ports/packages -type l -delete"
+Delete all broken symbolic links in
+.Pa /usr/ports/packages .
+.It Li "find /usr/src -name CVS -prune -o -depth +6 -print"
+Find files and directories that are at least seven levels deep
+in the working directory
+.Pa /usr/src .
+.It Li "find /usr/src -name CVS -prune -o -mindepth 7 -print"
+Is not equivalent to the previous example, since
+.Ic -prune
+is not evaluated below level seven.
.El
.Sh COMPATIBILITY
The
@@ -795,15 +811,19 @@ section below for details.
The
.Nm
utility syntax is a superset of the syntax specified by the
-.St -p1003.2
+.St -p1003.1-2001
standard.
.Pp
-All the single character options as well as the
+All the single character options except
+.Ic -H
+and
+.Ic -L
+as well as the
.Ic -iname , -inum , -iregex , -print0 , -delete , -ls ,
and
.Ic -regex
primaries are extensions to
-.St -p1003.2 .
+.St -p1003.1-2001 .
.Pp
Historically, the
.Fl d , L
diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c
index 4b3d2df..0486e8b 100644
--- a/usr.bin/find/find.c
+++ b/usr.bin/find/find.c
@@ -186,6 +186,11 @@ find_execute(PLAN *plan, char *paths[])
err(1, "ftsopen");
for (rval = 0; (entry = fts_read(tree)) != NULL;) {
+ if (maxdepth != -1 && entry->fts_level >= maxdepth) {
+ if (fts_set(tree, entry, FTS_SKIP))
+ err(1, "%s", entry->fts_path);
+ }
+
switch (entry->fts_info) {
case FTS_D:
if (isdepth)
@@ -225,12 +230,6 @@ find_execute(PLAN *plan, char *paths[])
* the work specified by the user on the command line.
*/
for (p = plan; p && (p->execute)(p, entry); p = p->next);
-
- if (maxdepth != -1 && entry->fts_level >= maxdepth) {
- if (fts_set(tree, entry, FTS_SKIP))
- err(1, "%s", entry->fts_path);
- continue;
- }
}
/* Finish any pending -exec ... {} + functions. */
for (p = plan; p != NULL; p = p->next)
diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h
index 2944278..59c70b6 100644
--- a/usr.bin/find/find.h
+++ b/usr.bin/find/find.h
@@ -57,6 +57,7 @@ typedef struct _plandata *creat_f(struct _option *, char ***);
#define F_TIME2_C 0x00000020 /* one of -newer?c */
#define F_TIME2_T 0x00000040 /* one of -newer?t */
#define F_MAXDEPTH F_TIME_A /* maxdepth vs. mindepth */
+#define F_DEPTH F_TIME_A /* -depth n vs. -d */
/* command line function modifiers */
#define F_EQUAL 0x00000000 /* [acm]min [acm]time inum links size */
#define F_LESSTHAN 0x00000100
@@ -86,6 +87,7 @@ typedef struct _plandata {
u_long _f_notflags;
} fl;
nlink_t _l_data; /* link count */
+ short _d_data; /* level depth (-1 to N) */
off_t _o_data; /* file size */
time_t _t_data; /* time value */
uid_t _u_data; /* uid */
@@ -109,6 +111,7 @@ typedef struct _plandata {
} PLAN;
#define a_data p_un._a_data
#define c_data p_un._c_data
+#define d_data p_un._d_data
#define fl_flags p_un.fl._f_flags
#define fl_notflags p_un.fl._f_notflags
#define g_data p_un._g_data
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index 72bf8aa..c0fb6e0 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <ctype.h>
#include "find.h"
@@ -462,11 +463,9 @@ c_delete(OPTION *option, char ***argvp __unused)
/*
- * -depth functions --
+ * always_true --
*
- * Always true, causes descent of the directory hierarchy to be done
- * so that all entries in a directory are acted on before the directory
- * itself.
+ * Always true, used for -maxdepth, -mindepth, -xdev and -follow
*/
int
f_always_true(PLAN *plan __unused, FTSENT *entry __unused)
@@ -474,12 +473,53 @@ f_always_true(PLAN *plan __unused, FTSENT *entry __unused)
return 1;
}
+/*
+ * -depth functions --
+ *
+ * With argument: True if the file is at level n.
+ * Without argument: Always true, causes descent of the directory hierarchy
+ * to be done so that all entries in a directory are acted on before the
+ * directory itself.
+ */
+int
+f_depth(PLAN *plan, FTSENT *entry)
+{
+ if (plan->flags & F_DEPTH)
+ COMPARE(entry->fts_level, plan->d_data);
+ else
+ return 1;
+}
+
PLAN *
-c_depth(OPTION *option, char ***argvp __unused)
+c_depth(OPTION *option, char ***argvp)
{
- isdepth = 1;
+ PLAN *new;
+ char *str;
- return palloc(option);
+ new = palloc(option);
+
+ str = **argvp;
+ if (str && !(new->flags & F_DEPTH)) {
+ /* skip leading + or - */
+ if (*str == '+' || *str == '-')
+ str++;
+ /* skip sign */
+ if (*str == '+' || *str == '-')
+ str++;
+ if (isdigit(*str))
+ new->flags |= F_DEPTH;
+ }
+
+ if (new->flags & F_DEPTH) { /* -depth n */
+ char *ndepth;
+
+ ndepth = nextarg(option, argvp);
+ new->d_data = find_parsenum(new, option->name, ndepth, NULL);
+ } else { /* -d */
+ isdepth = 1;
+ }
+
+ return new;
}
/*
diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c
index 2f3ca3a..12703e7 100644
--- a/usr.bin/find/option.c
+++ b/usr.bin/find/option.c
@@ -72,7 +72,7 @@ static OPTION const options[] = {
{ "-cnewer", c_newer, f_newer, F_TIME_C },
{ "-ctime", c_Xtime, f_Xtime, F_TIME_C },
{ "-delete", c_delete, f_delete, 0 },
- { "-depth", c_depth, f_always_true, 0 },
+ { "-depth", c_depth, f_depth, 0 },
{ "-empty", c_empty, f_empty, 0 },
{ "-exec", c_exec, f_exec, 0 },
{ "-execdir", c_exec, f_exec, F_EXECDIR },
OpenPOWER on IntegriCloud