- 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
This commit is contained in:
parent
e3aa81b84d
commit
1c8329632e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=129812
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
PLAN *
|
||||
c_depth(OPTION *option, char ***argvp __unused)
|
||||
/*
|
||||
* -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)
|
||||
{
|
||||
isdepth = 1;
|
||||
if (plan->flags & F_DEPTH)
|
||||
COMPARE(entry->fts_level, plan->d_data);
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
return palloc(option);
|
||||
PLAN *
|
||||
c_depth(OPTION *option, char ***argvp)
|
||||
{
|
||||
PLAN *new;
|
||||
char *str;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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 },
|
||||
|
Loading…
Reference in New Issue
Block a user