summaryrefslogtreecommitdiff
path: root/usr.bin/find
diff options
context:
space:
mode:
authorsvn2git <svn2git@FreeBSD.org>1994-05-01 08:00:00 +0000
committersvn2git <svn2git@FreeBSD.org>1994-05-01 08:00:00 +0000
commita16f65c7d117419bd266c28a1901ef129a337569 (patch)
tree2626602f66dc3551e7a7c7bc9ad763c3bc7ab40a /usr.bin/find
parent8503f4f13f77abf7adc8f7e329c6f9c1d52b6a20 (diff)
Diffstat (limited to 'usr.bin/find')
-rw-r--r--usr.bin/find/extern.h2
-rw-r--r--usr.bin/find/find.163
-rw-r--r--usr.bin/find/find.h2
-rw-r--r--usr.bin/find/function.c37
-rw-r--r--usr.bin/find/main.c3
-rw-r--r--usr.bin/find/option.c2
6 files changed, 87 insertions, 22 deletions
diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h
index 1f02f12bb477..6f5a29dad8e9 100644
--- a/usr.bin/find/extern.h
+++ b/usr.bin/find/extern.h
@@ -65,6 +65,8 @@ PLAN *c_nouser __P((void));
PLAN *c_path __P((char *));
PLAN *c_perm __P((char *));
PLAN *c_print __P((void));
+PLAN *c_print0 __P((void));
+PLAN *c_printf __P((char *));
PLAN *c_prune __P((void));
PLAN *c_size __P((char *));
PLAN *c_type __P((char *));
diff --git a/usr.bin/find/find.1 b/usr.bin/find/find.1
index b6ce6b9d58d2..49d4d7af4bdb 100644
--- a/usr.bin/find/find.1
+++ b/usr.bin/find/find.1
@@ -189,19 +189,6 @@ True if the difference between the file last modification time and the time
was started, rounded up to the next full 24\-hour period, is
.Ar n
24\-hour periods.
-.It Ic \&-ok Ar utility Ns Op argument ... ;
-The
-.Ic \&-ok
-primary is identical to the
-.Ic -exec
-primary with the exception that
-.Nm find
-requests user affirmation for the execution of the utility by printing
-a message to the terminal and reading a response.
-If the response is other than ``y'' the command is not executed and the
-value of the
-.Ar \&ok
-expression is false.
.It Ic -name Ar pattern
True if the last component of the pathname being examined matches
.Ar pattern .
@@ -217,6 +204,19 @@ True if the current file has a more recent last modification time than
True if the file belongs to an unknown user.
.It Ic -nogroup
True if the file belongs to an unknown group.
+.It Ic \&-ok Ar utility Ns Op argument ... ;
+The
+.Ic \&-ok
+primary is identical to the
+.Ic -exec
+primary with the exception that
+.Nm find
+requests user affirmation for the execution of the utility by printing
+a message to the terminal and reading a response.
+If the response is other than ``y'' the command is not executed and the
+value of the
+.Ar \&ok
+expression is false.
.It Ic -path Ar pattern
True if the pathname being examined matches
.Ar pattern .
@@ -258,12 +258,28 @@ Note, the first character of a symbolic mode may not be a dash (``\-'').
.It Ic -print
This primary always evaluates to true.
It prints the pathname of the current file to standard output.
-The expression is appended to the user specified expression if neither
+The expression is appended to the user specified expression if none of
.Ic -exec ,
-.Ic -ls
-or
+.Ic -ls ,
+.Ic -print0 ,
+.Ic -printf
+and
.Ic \&-ok
-is specified.
+are specified.
+.It Ic -print0
+This primary prints the pathname of the current file to standard output,
+followed by a NUL (ASCII 0) character. No newline is output. It
+is intended for use when the files being reported may contain newlines or
+other special characters.
+.It Ic -printf
+This primary takes one argument, which is interpreted as a format string
+to be passed to
+.Xr printf 3 .
+It must contain exactly one
+.Dq Li \&%s
+format specifier, with or without modifier flags, which receives the
+full pathname of the current file. No C-style escape processing is
+performed.
.It Ic -prune
This primary always evaluates to true.
It causes
@@ -375,14 +391,21 @@ and owned by ``wnj''.
.It Li "find / \e( -newer ttt -or -user wnj \e) -print"
Print out a list of all the files that are either owned by ``wnj'' or
that are newer than ``ttt''.
+.It Li "find / -name \e*~ -print0 | perl -n0e unlink"
+Find all the
+.Xr emacs 1
+backup files and delete them quickly using
+.Xr perl 1 .
.El
.Sh SEE ALSO
.Xr chmod 1 ,
.Xr locate 1 ,
+.Xr xargs 1 ,
.Xr stat 2 ,
.Xr fts 3 ,
.Xr getpwent 3 ,
.Xr getgrent 3 ,
+.Xr printf 3 ,
.Xr strmode 3 ,
.Xr symlink 7
.Sh STANDARDS
@@ -397,9 +420,11 @@ The
and
.Fl X
options and the
-.Ic -inum
+.Ic -inum ,
+.Ic -ls ,
+.Ic -print0 ,
and
-.Ic -ls
+.Ic -printf
primaries are extensions to
.St -p1003.2 .
.Pp
diff --git a/usr.bin/find/find.h b/usr.bin/find/find.h
index 4c4ffa54e9bd..43ac66a9e818 100644
--- a/usr.bin/find/find.h
+++ b/usr.bin/find/find.h
@@ -57,6 +57,8 @@ typedef struct _plandata {
#define F_MTFLAG 1 /* fstype */
#define F_MTTYPE 2
#define F_ATLEAST 1 /* perm */
+#define F_PRINT0 1
+#define F_PRINTF 2
int flags; /* private flags */
enum ntype type; /* plan node type */
union {
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index df053f9a188d..c56634f3e994 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -673,7 +673,7 @@ f_nogroup(plan, entry)
{
char *group_from_gid();
- return (group_from_gid(entry->fts_statp->st_gid, 1) ? 1 : 0);
+ return (group_from_gid(entry->fts_statp->st_gid, 1) ? 0 : 1);
}
PLAN *
@@ -697,7 +697,7 @@ f_nouser(plan, entry)
{
char *user_from_uid();
- return (user_from_uid(entry->fts_statp->st_uid, 1) ? 1 : 0);
+ return (user_from_uid(entry->fts_statp->st_uid, 1) ? 0 : 1);
}
PLAN *
@@ -790,7 +790,17 @@ f_print(plan, entry)
PLAN *plan;
FTSENT *entry;
{
- (void)printf("%s\n", entry->fts_path);
+ if (plan->flags & F_PRINTF) {
+ printf(plan->c_data, entry->fts_path);
+ } else {
+ fputs(entry->fts_path, stdout);
+ }
+
+ if (plan->flags & F_PRINT0) {
+ fputc('\0', stdout);
+ } else {
+ fputc('\n', stdout);
+ }
return (1);
}
@@ -801,6 +811,27 @@ c_print()
return (palloc(N_PRINT, f_print));
}
+
+PLAN *
+c_print0()
+{
+ PLAN *rv = palloc(N_PRINT, f_print);
+ rv->flags = F_PRINT0;
+ isoutput = 1;
+ return rv;
+}
+
+PLAN *
+c_printf(arg)
+ char *arg;
+{
+ PLAN *rv = palloc(N_PRINT, f_print);
+ rv->flags = F_PRINTF;
+ rv->c_data = arg;
+ isoutput = 1;
+ return rv;
+}
+
/*
* -prune functions --
diff --git a/usr.bin/find/main.c b/usr.bin/find/main.c
index 073a5f030def..19f6470761a0 100644
--- a/usr.bin/find/main.c
+++ b/usr.bin/find/main.c
@@ -113,6 +113,9 @@ main(argc, argv)
if ((dotfd = open(".", O_RDONLY, 0)) < 0)
err(1, ".:");
+ /* make output interperse properly with subprocesses */
+ setlinebuf(stdout);
+
find_execute(find_formplan(argv), start);
exit(0);
}
diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c
index 87337ca671d2..db142915d04a 100644
--- a/usr.bin/find/option.c
+++ b/usr.bin/find/option.c
@@ -77,6 +77,8 @@ static OPTION options[] = {
{ "-path", N_PATH, c_path, O_ARGV },
{ "-perm", N_PERM, c_perm, O_ARGV },
{ "-print", N_PRINT, c_print, O_ZERO },
+ { "-print0", N_PRINT, c_print0, O_ZERO },
+ { "-printf", N_PRINT, c_printf, O_ARGV },
{ "-prune", N_PRUNE, c_prune, O_ZERO },
{ "-size", N_SIZE, c_size, O_ARGV },
{ "-type", N_TYPE, c_type, O_ARGV },