.\"
.\" %sccs.include.redist.roff%
.\"
-.\" @(#)find.1 8.3 (Berkeley) %G%
+.\" @(#)find.1 8.4 (Berkeley) %G%
.\"
.Dd
.Dt FIND 1
.Nd walk a file hierarchy
.Sh SYNOPSIS
.Nm find
-.Op Fl HdhXx
+.Op Fl H | Fl L | Fl P
+.Op Fl Xdx
.Op Fl f Ar file
.Op Ar file ...
.Ar expression
The
.Fl H
option causes the file information and file type (see
-.Xr stat 2 ) ,
-returned for each symbolic link encountered on the command line to be
+.Xr stat 2)
+returned for each symbolic link specified on the command line to be
those of the file referenced by the link, not the link itself.
If the referenced file does not exist, the file information and type will
be for the link itself. File information of all symbolic links not on
the command line is that of the link itself.
+.It Fl L
+The
+.Fl L
+option causes the file information and file type (see
+.Xr stat 2)
+returned for each symbolic link to be those of the file referenced by the
+link, not the link itself.
+If the referenced file does not exist, the file information and type will
+be for the link itself.
+.It Fl P
+The
+.Fl P
+option causes the file information and file type (see
+.Xr stat 2)
+returned for each symbolic link to be those of the link itself.
+.It Fl X
+The
+.Fl X
+option is a modification to permit
+.Nm
+to be safely used in conjunction with
+.Xr xargs 1 .
+If a file name contains any of the delimiting characters used by
+.Xr xargs ,
+a diagnostic message is displayed on standard error, and the file
+is skipped.
+The delimiting characters include single (`` ' '') and double (`` " '')
+quotes, backslash (``\e''), space, tab and newline characters.
.It Fl d
The
.Fl d
to traverse.
File hierarchies may also be specified as the operands immediately
following the options.
-.It Fl h
-The
-.Fl h
-option causes the file information and file type (see
-.Xr stat 2 ) ,
-returned for each symbolic link to be those of the file referenced by the
-link, not the link itself.
-If the referenced file does not exist, the file information and type will
-be for the link itself.
-.It Fl X
-The
-.Fl X
-option is a modification to permit
-.Nm
-to be safely used in conjunction with
-.Xr xargs 1 .
-If a file name contains any of the delimiting characters used by
-.Xr xargs ,
-a diagnostic message is displayed on standard error, and the file
-is skipped.
-The delimiting characters include single (`` ' '') and double (`` " '')
-quotes, backslash (``\e''), space, tab and newline characters.
.It Fl x
The
.Fl x
.Xr locate 1 ,
.Xr stat 2 ,
.Xr fts 3 ,
-.Xr getpwent 3 ,
.Xr getgrent 3 ,
+.Xr getpwent 3 ,
.Xr strmode 3 ,
.Xr symlink 7
.Sh STANDARDS
/*-
- * Copyright (c) 1991, 1993
+ * Copyright (c) 1991, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
*/
#ifndef lint
-static char sccsid[] = "@(#)find.c 8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)find.c 8.2 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
* take a search plan and an array of search paths and executes the plan
* over all FTSENT's returned for the given search paths.
*/
-void
+int
find_execute(plan, paths)
PLAN *plan; /* search plan */
char **paths; /* array of pathnames to traverse */
{
register FTSENT *entry;
PLAN *p;
+ int rval;
- if (!(tree = fts_open(paths, ftsoptions, (int (*)())NULL)))
+ if ((tree = fts_open(paths, ftsoptions, (int (*)())NULL)) == NULL)
err(1, "ftsopen");
- while (entry = fts_read(tree)) {
- switch(entry->fts_info) {
+ for (rval = 0; (entry = fts_read(tree)) != NULL;) {
+ switch (entry->fts_info) {
case FTS_D:
if (isdepth)
continue;
case FTS_ERR:
case FTS_NS:
(void)fflush(stdout);
+ errno = entry->fts_errno;
warn("%s", entry->fts_path);
+ rval = 1;
continue;
}
#define BADCH " \t\n\\'\""
if (isxargs && strpbrk(entry->fts_path, BADCH)) {
(void)fflush(stdout);
warnx("%s: illegal path", entry->fts_path);
+ rval = 1;
continue;
}
/*
- * call all the functions in the execution plan until one is
+ * Call all the functions in the execution plan until one is
* false or all have been executed. This is where we do all
* the work specified by the user on the command line.
*/
for (p = plan; p && (p->eval)(p, entry); p = p->next);
}
- (void)fts_close(tree);
+ if (errno)
+ err(1, "fts_read");
+ return (rval);
}
/*-
- * Copyright (c) 1990, 1993
+ * Copyright (c) 1990, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
+ * This code is derived from software contributed to Berkeley by
+ * Cimarron D. Taylor of the University of California, Berkeley.
+ *
* %sccs.include.redist.c%
*/
#ifndef lint
-static char sccsid[] = "@(#)main.c 8.1 (Berkeley) %G%";
+char copyright[] =
+"@(#) Copyright (c) 1990, 1993, 1994\n\
+ The Regents of the University of California. All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)main.c 8.2 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
char *argv[];
{
register char **p, **start;
- int ch;
+ int Hflag, Lflag, Pflag, ch;
(void)time(&now); /* initialize the time-of-day */
p = start = argv;
- ftsoptions = FTS_NOSTAT|FTS_PHYSICAL;
- while ((ch = getopt(argc, argv, "Hdf:hXx")) != EOF)
- switch(ch) {
+ Hflag = Lflag = Pflag = 0;
+ ftsoptions = FTS_NOSTAT | FTS_PHYSICAL;
+ while ((ch = getopt(argc, argv, "HLPXdf:x")) != EOF)
+ switch (ch) {
case 'H':
- ftsoptions |= FTS_COMFOLLOW;
+ Hflag = 1;
+ Lflag = Pflag = 0;
+ break;
+ case 'L':
+ Lflag = 1;
+ Hflag = Pflag = 0;
+ break;
+ case 'P':
+ Pflag = 1;
+ Hflag = Lflag = 0;
+ break;
+ case 'X':
+ isxargs = 1;
break;
case 'd':
isdepth = 1;
case 'f':
*p++ = optarg;
break;
- case 'h':
- ftsoptions &= ~FTS_PHYSICAL;
- ftsoptions |= FTS_LOGICAL;
- break;
- case 'X':
- isxargs = 1;
- break;
case 'x':
ftsoptions |= FTS_XDEV;
break;
argc -= optind;
argv += optind;
+ if (Hflag)
+ ftsoptions |= FTS_COMFOLLOW;
+ if (Lflag) {
+ ftsoptions &= ~FTS_PHYSICAL;
+ ftsoptions |= FTS_LOGICAL;
+ }
+
/* Find first option to delimit the file list. */
- while (*argv) {
+ for (; *argv != NULL; *p++ = *argv++)
if (option(*argv))
break;
- *p++ = *argv++;
- }
if (p == start)
usage();
*p = NULL;
if ((dotfd = open(".", O_RDONLY, 0)) < 0)
- err(1, ".:");
+ err(1, ".");
- find_execute(find_formplan(argv), start);
- exit(0);
+ exit(find_execute(find_formplan(argv), start));
}
static void
usage()
{
(void)fprintf(stderr,
- "usage: find [-HdhXx] [-f file] [file ...] expression\n");
+"usage: find [-H | -L | -P] [-Xdx] [-f file] [file ...] [expression]\n");
exit(1);
}
-
-
-
-
-
-
-
-
-