History log of /freebsd-current/usr.bin/find/function.c
Revision Date Author Comments
# e4b646ce 21-Jan-2024 Ricardo Branco <rbranco@suse.de>

find: Add -readable, -writable & -executable options

Reviewed by: jhb, Mina Galić
Pull Request: https://github.com/freebsd/freebsd-src/pull/1080


# 2a121b97 15-Jan-2024 Ricardo Branco <rbranco@suse.de>

find: Allow '/' to be used with -perm for GNU compatibility

In 2005, Gnu find deprecated '+' as the leading character for the -perm
argument, instead preferring '/' with the same meaning. Implement that
behavior here, and document it in the man page.

Reviewed by: imp, emaste
Pull Request: https://github.com/freebsd/freebsd-src/pull/1060


# 5e3934b1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# bdcbfde3 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# b422540a 01-Jul-2018 Eitan Adler <eadler@FreeBSD.org>

find(1): deLINTify


# c3a6ea5b 06-Feb-2018 Alex Richardson <arichardson@FreeBSD.org>

Allow compiling usr.bin/find on Linux and Mac

When building FreeBSD the makefiles invoke find with various flags such as
`-s` that aren't supported in the native /usr/bin/find. To fix this I
build the FreeBSD version of find and use that when crossbuilding.

Inserting lots if #ifdefs in the code is rather ugly but I don't see a
better solution.

Reviewed By: brooks (mentor)
Approved By: jhb (mentor)
Differential Revision: https://reviews.freebsd.org/D13306


# d8a0fe10 29-Dec-2017 Conrad Meyer <cem@FreeBSD.org>

find(1): Fix -newer and -samefile to conform to POSIX[0]

By default, or with the -P flag, find(1) should evaluate paths "physically."
For symlinks, this means using the link itself instead of the target.

Historically (since the import of BSD 4.4-lite from CSRG), find(1) has
failed to refer to the link itself, at least for -newer and -samefile.

[0]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html

PR: 222698
Reported by: Harald Schmalzbauer <bugzilla.freebsd AT omnilan.de>
Sponsored by: Dell EMC Isilon


# 8a16b7a1 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

General further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.


# 0ab69d71 11-Nov-2017 Xin LI <delphij@FreeBSD.org>

find(1): Don't treat statfs() error as fatal in f_fstype, which can happen
when a directory is removed in the middle of find.

Instead of a full err(), allow find to continue, plus print a warning with
exitstatus set when appropriate.

Reported by: 100.chksetuid via gordon
Reviewed by: jilles
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D13024


# fbbd9655 28-Feb-2017 Warner Losh <imp@FreeBSD.org>

Renumber copyright clause 4

Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by: Jan Schaumann <jschauma@stevens.edu>
Pull Request: https://github.com/freebsd/freebsd/pull/96


# 26ac9660 18-Apr-2016 Marcelo Araujo <araujo@FreeBSD.org>

Use NULL instead of 0 for pointers.

MFC after: 2 weeks.


# 599df3ef 08-Oct-2014 Ed Maste <emaste@FreeBSD.org>

Correct scale factor for T terabyte suffix

PR: 194250
MFC after: 3 days
Sponsored by: The FreeBSD Foundation


# 2545695e 13-Apr-2014 Christian Brueffer <brueffer@FreeBSD.org>

Avoid double free in f_acl().

CID: 1018508
Found with: Coverity Prevent(tm)
MFC after: 1 week


# b547523e 13-Apr-2014 Jilles Tjoelker <jilles@FreeBSD.org>

find: Return normal exit status from -quit.

If there was an error, make the exit status reflect this even if -quit
caused the exit. Formerly, -quit always caused exit(0).

GNU find does the same.


# 7a79617c 12-Apr-2014 Jilles Tjoelker <jilles@FreeBSD.org>

find: Correctly propagate -exec/-execdir ... {} + exit status.

As per POSIX, the -exec ... {} + primary always returns true, but a non-zero
exit status causes find to return a non-zero exit status itself. GNU does
the same, and also for -execdir ... {} +.

It does not make much sense to return false from the primary only when the
child process happens to be run.

The behaviour for -exec/-execdir ... ; remains unchanged: the primary
returns true or false depending on the exit status, and find's exit status
is unaffected.


# cf599562 16-Mar-2014 Jilles Tjoelker <jilles@FreeBSD.org>

find: When performing -quit, finish pending -exec ... + command lines.

This avoids unexpected partial processing when a find command uses both
-quit and -exec ... +.

GNU find does the same.

MFC after: 1 week


# b95de98a 11-Jan-2014 Jilles Tjoelker <jilles@FreeBSD.org>

find: Allow -type d without statting everything.

fts(3) detects directories even in FTS_NOSTAT mode (so it can descend into
them).

No functional change is intended, but find commands that use -type d but no
primaries that still require stat/lstat calls make considerably fewer system
calls.


# e810bef7 05-Jan-2014 Jilles Tjoelker <jilles@FreeBSD.org>

find: Fix two more problems with -lname and -ilname:

* Do not match symlinks that are followed because of -H or -L. This is
explicitly documented in GNU find's info file and is like -type l.

* Fix matching symlinks in subdirectories when fts changes directories.

Also, avoid some readlink() calls on files that are obviously not symlinks
(because of fts(3) restrictions, not all of them).

MFC after: 1 week


# 3e02329a 05-Jan-2014 Jilles Tjoelker <jilles@FreeBSD.org>

find: Fix -lname and -ilname.

The code did not take into account that readlink() does not add a
terminating '\0', and therefore did not work reliably.

As before, symlinks of length PATH_MAX or more are not handled correctly.
(These can only be created on other operating systems.)

PR: bin/185393
Submitted by: Ben Reser (original version)
MFC after: 1 week


# 9d6d5a71 02-Aug-2013 Jilles Tjoelker <jilles@FreeBSD.org>

find: Allow -delete to delete files given as arguments.

Formerly, a command like find dir1/dir2 -delete would delete everything
under dir1/dir2 but not dir1/dir2 itself.

When -L is not specified and "." can be opened, the fts(3) code underlying
find(1) is careful to avoid following symlinks or being dropped in different
locations by moving the directory fts is currently traversing. If a
problematic concurrent modification is detected, fts will not enter the
directory or abort. Files found in the search are returned via the current
working directory and a pathname not containing a slash.

For paranoia, find(1) verifies this when -delete is used. However, it is too
paranoid about the root of the traversal. It is already assumed that the
initial pathname does not refer to directories or symlinks that might be
replaced by untrusted users; otherwise, the whole traversal would be unsafe.
Therefore, it is not necessary to do the check for fts_level ==
FTS_ROOTLEVEL.

Deleting the pathnames given as arguments can be prevented without error
messages using -mindepth 1 or by changing directory and passing "." as
argument to find. This works in the old as well as the new version of find.

Tested by: Kurt Lidl
Reviewed by: jhb


# ddd956b0 17-Mar-2013 Jilles Tjoelker <jilles@FreeBSD.org>

find: Include nanoseconds when comparing timestamps of files.

When comparing to the timestamp of a given file using -newer, -Xnewer and
-newerXY (where X and Y are one of m, c, a, B), include nanoseconds in the
comparison.

The primaries that compare a timestamp of a file to a given value (-Xmin,
-Xtime, -newerXt) continue to compare times in whole seconds.

Note that the default value 0 of vfs.timestamp_precision almost always
causes the nanoseconds part to be 0. However, touch -d can set a timestamp
to the microsecond regardless of that sysctl.

MFC after: 1 week


# 9ed0c92c 03-Mar-2013 David Malone <dwmalone@FreeBSD.org>

Add an option for finding sparse files.

Reviewed by: iedowse
MFC after: 3 weeks


# 17ef6d3a 10-Feb-2013 Jilles Tjoelker <jilles@FreeBSD.org>

find: Run when cwd cannot be opened, except with -execdir or -delete.

fts(3) can run (albeit more slowly and imposing the {PATH_MAX} limit) when
the current directory cannot be opened. Therefore, do not make a failure to
open the current directory (for returning to it later in -exec) fatal.

If -execdir or -delete are used, the expectation is that fts(3) will use
chdir to avoid race conditions (except for -execdir with -L). Do not break
this expectation any more than it already is by still failing if the current
directory cannot be opened.


# bc626176 10-Feb-2013 Jilles Tjoelker <jilles@FreeBSD.org>

find: In -execdir ... {} +, only pass one file per invocation.

This is inefficient but ensures that -execdir ... {} + does not mix files
from different directories in one invocation; the command could not access
some files. Files from the same directory should really be handled in one
invocation but this is somewhat more complicated.


# 40072dc2 25-Jul-2012 Jilles Tjoelker <jilles@FreeBSD.org>

find: Implement real -ignore_readdir_race.

If -ignore_readdir_race is present, [ENOENT] errors caused by deleting a
file after find has read its name from a directory are ignored.

Formerly, -ignore_readdir_race did nothing.

PR: bin/169723
Submitted by: Valery Khromov and Andrey Ignatov


# 6ab780e5 12-Jun-2011 Tai-hwa Liang <avatar@FreeBSD.org>

Using statfs.f_fstypename rather than statfs.f_type whilst performing fstype
comparsion as nullfs will copy f_type from underlayer FS.

PR: bin/156258
Submitted by: Marcin Wisnicki <mwisnicki+freebsd@gmail.com>
MFC after: 1 month


# da52b4ca 11-Dec-2010 Joel Dahl <joel@FreeBSD.org>

Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with: imp, rwatson


# e66a677b 01-Dec-2010 Kevin Lo <kevlo@FreeBSD.org>

Don't error out while searching for empty directories.

Submitted by: Bakul Shah <bakul at bitblocks dot com>


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 3549ef2f 06-May-2010 Xin LI <delphij@FreeBSD.org>

Revert r207677 which is considered a violation of style(9).

Pointed out by: bde
Pointy hat to: delphij


# d18129ea 05-May-2010 Xin LI <delphij@FreeBSD.org>

Move SCCS tags to comments as they were already #if 0'ed.


# 27dfb536 17-Mar-2010 Gavin Atkinson <gavin@FreeBSD.org>

Merge r203865 from head:

The -newerXB option was being interpreted the same as the -newerXm option
as a check for F_TIME2_B was missing. Fix this.

PR: bin/138245
Submitted by: "David E. Cross" <crossd cs.rpi.edu>


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 8310a1a2 13-Feb-2010 Gavin Atkinson <gavin@FreeBSD.org>

The -newerXB option was being interpreted the same as the -newerXm option
as a check for F_TIME2_B was missing. Fix this.

PR: bin/138245
Submitted by: "David E. Cross" <crossd cs.rpi.edu>
MFC after: 1 month


# 65bcaaec 09-Feb-2010 Ed Schouten <ed@FreeBSD.org>

Don't let find(1) depend on struct timeb.

This structure is deprecated and only used by ftime(2), which is part of
libcompat. The second argument of get_date() is unused, which means we
can just remove it entirely.


# 4e86d39d 30-Jan-2010 Edward Tomasz Napierala <trasz@FreeBSD.org>

MFC r196839:

Add NFSv4 ACL support to find(1).


# 10bc3a7f 29-Dec-2009 Ed Schouten <ed@FreeBSD.org>

ANSIfy almost all applications that use WARNS=6.

I was considering committing all these patches one by one, but as
discussed with brooks@, there is no need to do this. If we ever
need/want to merge these changes back, it is still possible to do this
per application.


# fa2db914 04-Sep-2009 Edward Tomasz Napierala <trasz@FreeBSD.org>

Add NFSv4 ACL support to find(1).

Reviewed by: rwatson


# 6911f596 30-May-2009 Jilles Tjoelker <jilles@FreeBSD.org>

rm, find -delete: fix removing symlinks with uchg/uappnd set.

Formerly, this tried to clear the flags on the symlink's target
instead of the symlink itself.

As before, this only happens for root or for the unlink(1) variant of rm.

PR: bin/111226 (part of)
Submitted by: Martin Kammerhofer
Approved by: ed (mentor)
MFC after: 3 weeks


# 05e605b7 19-May-2009 Andriy Gapon <avg@FreeBSD.org>

find: do not silently disable -L when -delete is used

First of all, current behavior is not documented and confusing,
and it can be very dangerous in the following sequence:
find -L . -type l
find -L . -type l -delete
(the second line is even suggested by find(1)).

Instead simply refuse to proceed when -L and -delete are both used.
A descriptive error message is provided.
The following command can be safely used to remove broken links:
find -L . -type l -print0 | xargs rm -0

To do: update find(1)
PR: bin/90687
Obtained from: Anatoli Klassen <anatoli@aksoft.net>
Approved by: jhb (mentor)


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# acebb585 23-Feb-2008 Warner Losh <imp@FreeBSD.org>

The matching in -lname and -ilname are on the contents of the link
itself, not on the type of the file. As such, do a readlink to get
the symbolic link's contents and fail to match if the path isn't a
symbolic link.

Pointed out by: des@


# 46b993ff 23-Feb-2008 Warner Losh <imp@FreeBSD.org>

Implement a number of primaries present in GNU find, but not present
in our find.

The following are nops because they aren't relevant to our find:
-ignore_readdir_race
-noignore_readdir_race
-noleaf
The following aliaes were created:
-gid -> -group [2]
-uid -> -user [2]
-wholename -> -path
-iwholename -> ipath
-mount -> -xdev
-d -> -depth [1]
The following new primaries were created:
-lname like -name, but matches symbolic links only)
-ilname like -lname but case insensitive
-quit exit(0)
-samefile returns true for hard links to the specified file
-true Always true
I changed one primary to match GNU find since I think our use of it violates
POLA
-false Always false (was an alias for -not!)

Also, document the '+' modifier for -execdir, as well as all of the above.
This was previously implemented.

Document the remaining 7 primaries that are in GNU find, but aren't yet
implemented in find(1)

[1] This was done in GNU find for compatibility with FreeBSD, yet they
mixed up command line args and primary args.

[2] -uid/-gid in GNU find ONLY takes a numeric arg, but that arg does the
normal range thing that. GNU find -user and -uid also take a numberic arg,
but don't do the range processing. find(1) does both for -user and -group,
so making -uid and -gid aliases is compatible for all non-error cases used
in GNU find. While not perfect emulation, this seems a reasonable thing
for us.


# 5a890aac 27-May-2006 Kirill Ponomarev <krion@FreeBSD.org>

Add the capability for a trailing scale indicator to cause the
specified size to be read in the more familiar units of kilobytes,
megabytes, gigabytes, terabytes and petabytes.

PR: bin/50988
Submitted by: Matthew Seaman <m.seaman@infracaninophile.co.uk>
MFC after: 7 days


# 4ba3b38b 25-May-2006 Kirill Ponomarev <krion@FreeBSD.org>

Enable numeric arguments and +/- prefixes with -user (-group)
options.

PR: bin/71513
Submitted by: Andre Albsmeier <Andre.Albsmeier@siemens.com>
MFC after: 7 days


# 22170420 14-May-2006 Kirill Ponomarev <krion@FreeBSD.org>

The last execution of -exec {} + is not done if the -exec primary is
not on the top-level -and sequence, e.g. inside of ! or -or.

Create a separate linked list of all active -exec {} + primaries and
do the last execution for all at termination.

PR: bin/79263
Submitted by: Jilles Tjoelker <jilles@stack.nl>
MFC after: 7 days


# 31d53425 03-Apr-2006 Ceri Davies <ceri@FreeBSD.org>

Add -Btime, -Bnewer, -Bmin, -newerB[Bacmt], -newer[acmt]B options to
work with the st_birthtime field of struct stat.

'B' has been chosen to match the format specifier from stat(1).

Approved by: jhb
MFC after: 2 weeks


# 8a0a76b8 25-Aug-2005 Ollivier Robert <roberto@FreeBSD.org>

Fixes for gcc4.x.

Submitted by: Divacky Roman <xdivac02@stud.fit.vutbr.cz>
PR: bin/84991


# 46c2bd61 25-Jan-2005 Suleiman Souhlal <ssouhlal@FreeBSD.org>

- Make find(1) WARNS?= 6 clean
- Bump to WARNS?= 6

Approved by: stefanf, grehan (mentor)


# e22bb9db 28-Jul-2004 Tim J. Robbins <tjr@FreeBSD.org>

Change the 'no terminating ";"' error message to 'no terminating ";" or "+"'
since + is also a valid way to terminate -exec.


# cc416533 28-Jul-2004 Tim J. Robbins <tjr@FreeBSD.org>

Remove partial support for building this on NetBSD.


# 1c832963 28-May-2004 Oliver Eikemeier <eik@FreeBSD.org>

- 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


# 9c5d31df 03-Apr-2004 Bosko Milekic <bmilekic@FreeBSD.org>

Give find(1) the option -acl to locate files with extended
ACLs. This is similar to what ls(1) can do. It is handy to
have it so that it can be used in conjunction with
"-exec setfacl {} \;" (to find(1)), among others.

This is the submitter's patch, but slightly modified.

PR: bin/65016
Submitted by: Christian S.J. Peron <maneo@bsdpro.com>


# ef646f18 14-Jun-2003 Mark Murray <markm@FreeBSD.org>

Fix all WARNS. Checked with "make WARNS=9". Remove unused file.


# 5965373e 10-Aug-2002 Maxime Henrion <mux@FreeBSD.org>

- Introduce a new struct xvfsconf, the userland version of struct vfsconf.
- Make getvfsbyname() take a struct xvfsconf *.
- Convert several consumers of getvfsbyname() to use struct xvfsconf.
- Correct the getvfsbyname.3 manpage.
- Create a new vfs.conflist sysctl to dump all the struct xvfsconf in the
kernel, and rewrite getvfsbyname() to use this instead of the weird
existing API.
- Convert some {set,get,end}vfsent() consumers to use the new vfs.conflist
sysctl.
- Convert a vfsload() call in nfsiod.c to kldload() and remove the useless
vfsisloadable() and endvfsent() calls.
- Add a warning printf() in vfs_sysctl() to tell people they are using
an old userland.

After these changes, it's possible to modify struct vfsconf without
breaking the binary compatibility. Please note that these changes don't
break this compatibility either.

When bp will have updated mount_smbfs(8) with the patch I sent him, there
will be no more consumers of the {set,get,end}vfsent(), vfsisloadable()
and vfsload() API, and I will promptly delete it.


# a07af811 13-Jul-2002 Tim J. Robbins <tjr@FreeBSD.org>

Account for space used by environment variables in a similar way to
xargs(1) when handling -exec ... {} + constructions.


# 5e25d888 01-Jun-2002 Tim J. Robbins <tjr@FreeBSD.org>

Support the SysV-style -exec utility args.. {} + function, required by
SUSv3. This is similar to find foo -print0 | xargs -0 utility args.


# 47bca8b0 16-May-2002 Juli Mallett <jmallett@FreeBSD.org>

Clean up malloc(3)'s argument. Remove casts which do nothing when we're
using sizeof() anyway. Use slightly more consistent (per-file) error
reporting for malloc(3) returning NULL. If "malloc failed" was being printed,
don't use err(3). If a NULL format is being used, use err(3). In one case
errx(3) was being used with strerror(3), so just use err(3).


# 46c2a2cf 15-May-2002 Tom Rhodes <trhodes@FreeBSD.org>

More consistancy. file system > filesystem


# 48d09ba6 02-Apr-2002 Mark Murray <markm@FreeBSD.org>

There is breakage in parsedate, so revert to get_date until this can be
resolved.

Reported by: paul


# 51b0534f 02-Apr-2002 Juli Mallett <jmallett@FreeBSD.org>

Fix find -exec with no command specified (i.e.: find . -exec ';')

PR: bin/36521
Submitted by: Simon 'corecode' Schubert <corecode@corecode.ath.cx>
Reviewed by: mike
MFC after: 3 days


# 3077469e 01-Apr-2002 David E. O'Brien <obrien@FreeBSD.org>

Fix SCM IDs.


# 9725a7b9 25-Mar-2002 Philippe Charnier <charnier@FreeBSD.org>

spelling


# 2a66bf16 21-Mar-2002 Mark Murray <markm@FreeBSD.org>

Restructure for own parsedate (replacement for get_date from CVS).

Fix up parsedate.y for WARNS=4.

Reviewd by: bde (except for parsedate.y diffs)


# ecca1f1c 20-Mar-2002 Mark Murray <markm@FreeBSD.org>

Remove __P().


# e98080b1 27-Feb-2002 David Malone <dwmalone@FreeBSD.org>

1) Remove -Wall from Makefile.
2) WARNs fixes (rename option to lookup_option to avoid shadowing, rename
argv to argv1 to avoid shadowing, const stuff, prototypes, __unused).
3) Remove "register"s.


# 631a8765 14-Sep-2001 Ruslan Ermilov <ru@FreeBSD.org>

Simplify f_Xtime().


# adff4fca 13-Sep-2001 Ruslan Ermilov <ru@FreeBSD.org>

Bloat find(1) even more, and introduce the concept
of time units to be used with -[acm]time primaries.

Based on patch from Nils M Holm <nmh@t3x.org>.

PR: bin/29165, bin/30309


# 7fd5ee41 04-Sep-2001 Ruslan Ermilov <ru@FreeBSD.org>

The implementation of -flags was broken and did not match the (poorly)
documented behavior. Only a certain set of file flags were recognized,
and "no" flags did not match files that have corresponding flags bits
turned off.

Fix and extend the -flags functionality as follows:

: -flags [-|+]<flags>,<notflags>
: The flags are specified using symbolic names (see chflags(1)).
: Those with the "no" prefix (except "nodump") are said to be
: <notflags>. Flags in <flags> are checked to be set, and flags in
: <notflags> are checked to be not set. Note that this is different
: from -perm, which only allows the user to specify mode bits that
: are set.
:
: If flags are preceded by a dash (``-''), this primary evaluates
: to true if at least all of the bits in <flags> and none of the bits
: in <notflags> are set in the file's flags bits. If flags are pre-
: ceded by a plus (``+''), this primary evaluates to true if any of
: the bits in <flags> is set in the file's flags bits, or any of the
: bits in <notflags> is not set in the file's flags bits. Otherwise,
: this primary evaluates to true if the bits in <flags> exactly match
: the file's flags bits, and none of the <flags> bits match those of
: <notflags>.

MFC after: 2 weeks


# c0ff9709 30-Aug-2001 Ruslan Ermilov <ru@FreeBSD.org>

Restore the `-perm +mode' feature.

Broken in the "close a PR" race, in revision 1.30.
Note that the patch in the PR did not have this bug!


# f0cb9537 24-Jul-2001 David E. O'Brien <obrien@FreeBSD.org>

Remove emalloc and expand to the malloc + error checking it was, where used.


# ea92232a 03-May-2001 Poul-Henning Kamp <phk@FreeBSD.org>

They add the following commands:
-anewer
-cnewer
-mnewer
-okdir
-newer[acm][acmt]

With it, you can form queries like

find . -newerct '1 minute ago' -print

As an extra bonus, the program is ANSI-fied - the original version
relies on some obscure features of K&R C.

(This PR was submitted in 1999, and the submittor has kept the patch
updated ever since, hats off for him guys, and how about you close a PR ??)

PR: 9374
Submitted by: Martin Birgmeier <Martin.Birgmeier@aon.at>


# 7c1d4b3a 23-Feb-2001 Akinori MUSHA <knu@FreeBSD.org>

Implement the following options and primaries:

-E Interpret regular expressions followed by -regex and -iregex op-
tions as extended (modern) regular expressions rather than basic
regular expressions (BRE's). The re_format(7) manual page fully
describes both formats.

-iname pattern
Like -name, but the match is case insensitive.

-ipath pattern
Like -path, but the match is case insensitive.

-regex pattern
True if the whole path of the file matches pattern using regular
expression. To match a file named ``./foo/xyzzy'', you can use
the regular expression ``.*/[xyz]*'' or ``.*/foo/.*'', but not
``xyzzy'' or ``/foo/''.

-iregex pattern
Like -regex, but the match is case insensitive.

These are meant to be compatible with other find(1) implementations
such as GNU's or NetBSD's except regexp library differences.

Reviewed by: sobomax, dcs, and some other people on -current


# ed1a4621 23-Jan-2001 Peter Wemm <peter@FreeBSD.org>

Add the -empty flag, from OpenBSD. It returns true if the directory
is empty. There doesn't appear to be another easy way to do this.

mobile# mkdir foo
mobile# mkdir foo/bar
mobile# mkdir bar
mobile# find . -empty
./foo/bar
./bar


# 1e2f8412 28-Jul-2000 Eivind Eklund <eivind@FreeBSD.org>

Make passing unknown fstypes to -fstype result in a warning instead of
an error. As it was, which find command lines that would work (be
accepted at all) was dependent on the presently running kernel, making
script writing and porting hard.


# 141d77b8 17-Jun-2000 Josef Karthauser <joe@FreeBSD.org>

Switch over to using the new fflagstostr and strtofflags library calls.


# c4b8db00 14-Jun-2000 Ollivier Robert <roberto@FreeBSD.org>

Make find -Wall -Wredundant-decls clean.

Submitted by: nrahlstr


# c76bc8f3 12-Jun-2000 Ollivier Robert <roberto@FreeBSD.org>

This patch adds the -mindepth and -maxdepth options to find(1), which
behave as in GNU find (and of course as described in the manual page
diff included). I think these options would be useful for some people.

Some missing $FreeBSD$ tags are also added.

The patch was slightly modified (send-pr mangling of TABS).

PR: bin/18941
Submitted by: Ben Smithurst <ben@scientia.demon.co.uk>


# 9d2796c3 12-Jun-2000 Ollivier Robert <roberto@FreeBSD.org>

The find -perm option currently supports an exact match,
or if the mode is preceded by a '-', it checks for a match
in at least the bits specified on the command line. It is
often desirable to find things with any execute or setuid or
setgid bits set.

PR: bin/10169
Submitted by: Monte Mitzelfelt <monte@gonefishing.org>


# 418d67b0 05-Feb-2000 Josef Karthauser <joe@FreeBSD.org>

Revert part of the last commit, remove {g|s}etflags from the libc
interface, and statically link them to the programs using them.
These functions, upon reflection and discussion, are too generically
named for a library interface with such specific functionality.
Also the api that they use, whilst ok for private use, isn't good
enough for a libc function.

Additionally there were complications with the build/install-world
process. It depends heavily upon xinstall, which got broken by
the change in api, and caused bootstrap problems and general mayhem.

There is work in progress to address future problems that may be
caused by changes in install-chain tools, and better names for
{g|s}etflags can be derived when some future program requires them.
For now the code has been left in src/lib/libc/gen (it started off
in src/bin/ls).

It's important to provide library functions for manipulating file
flag strings if we ever want this interface to be adopted outside
of the source tree, but now isn't necessarily the right moment
with 4.0-release just around the corner.

Approved: jkh


# 18c0eedd 27-Jan-2000 Josef Karthauser <joe@FreeBSD.org>

Historically file flags (schg, uschg, etc) have been converted from
string to u_long and back using two functions, flags_to_string and
string_to_flags, which co-existed with 'ls'. As time has progressed
more and more other tools have used these private functions to
manipulate the file flags.

Recently I moved these functions from /usr/src/bin/ls to libutil,
but after some discussion with bde it's been decided that they
really ought to go in libc.

There are two already existing libc functions for manipulating file
modes: setmode and getmode. In keeping with these flags_to_string
has been renamed getflags and string_to_flags to setflags.

The manual page could probably be improved upon ;)


# 567664c4 19-Dec-1999 Ollivier Robert <roberto@FreeBSD.org>

Second part of bin/3648: add -flags to search for specific flags.
I added $FreeBSD$ whicle I was here. The patch wasn't usable anymore
due to its age so I adapted it.

PR: bin/3648
Submitted by: Martin Birgmeier <mbirg@austria.ds.philips.com>


# 389017e5 06-Sep-1999 Bill Fumerola <billf@FreeBSD.org>

-Wall: remove unused variable, initialize variable to avoid gcc stupidity.


# 83268d4d 15-Dec-1998 Warner Losh <imp@FreeBSD.org>

Return memory from setmode.

Obtained from: OpenBSD


# 1fd98d7d 13-Oct-1998 Dag-Erling Smørgrav <des@FreeBSD.org>

Calls one or more of malloc(), warn(), err(), syslog(), execlp() or
execvp() in the child branch of a vfork(). Changed to use fork()
instead.

Some of these (mv, find, apply, xargs) might benefit greatly from
being rewritten to use vfork() properly.

PR: Loosely related to bin/8252
Approved by: jkh and bde


# 94aacc4f 10-Jan-1998 John Birrell <jb@FreeBSD.org>

A partial frontal lobotomy for find if using the NetBSD libc which
doesn't know about getvfsbyname() and the vfsconf structure. This
disables the -fstype option if compiled with a pre-processor that
defines __NetBSD__. With the FreeBSD built pre-processor, find can only
be built with the FreeBSD libc. So when running with a NetBSD kernel,
FreeBSD's libc will have to return ENOSYS for things that NetBSD
doesn't support. That's life in a hybrid world.


# 3f5223f8 13-Oct-1997 Wolfram Schneider <wosch@FreeBSD.org>

Add the primaries -mmin, -amin, -cmin to find, similar to the GNU find.


# 127d7563 29-Aug-1997 Warner Losh <imp@FreeBSD.org>

Add -execdir which will execute the exec command in the dir of the file
in question. This change and the fts changes should be merged into 2.2-stable
as soon as they are vetted in -current. This should allow cleaning of files
in /tmp to be reneabled.
Obtained from: OpenBSD


# 9d08e419 26-Mar-1997 Peter Wemm <peter@FreeBSD.org>

Fix "-fstype local" that was broken by another bugfix in the Lite2 merge.

Submitted by: Dmitrij Tejblum <dima@tejblum.dnttm.rssi.ru>, PR#3076


# 841484cd 11-Mar-1997 Peter Wemm <peter@FreeBSD.org>

Merge from Lite2 - use new getvfsbyname() and related changes.
understand whiteouts (FTS_W from fts()).


# 0da30e9a 11-Mar-1997 Peter Wemm <peter@FreeBSD.org>

Import some parts of CSRG 4.4BSD-Lite2 usr.bin sources to fix tree build.


# fa363c34 28-Jan-1997 Wolfram Schneider <wosch@FreeBSD.org>

The option "fstype" does not handle the argument "msdos" correctly.
This error results from changing the name for the msdos file system
from "pcfs" to "msdos". Close PR #1105

submitted by: Thomas Wintergerst <thomas@lemur.nord.de>,
Slaven Rezic <eserte@cs.tu-berlin.de>


# 3598e52c 05-Oct-1996 Peter Wemm <peter@FreeBSD.org>

With -delete, don't complain about non-empty directories. Otherwise
"cd /tmp; find . -mtime +7 -delete" is excessively noisy.


# 242ab807 05-Oct-1996 Peter Wemm <peter@FreeBSD.org>

For the -delete option, emulate the behavior of "rm -f" when dealing with
user-immutable files.

Requested by: ache


# abacbbbf 03-Oct-1996 Peter Wemm <peter@FreeBSD.org>

Implement a -delete option to find. The code is extremely paranoid and
goes to a fair degree of trouble to enable something like this to
be safe: cd /tmp && find . -mtime +7 -delete

It removes both files and directories. It does not attempt to remove
immutable files (an earlier version I showed to a few people did a chflags
and tried to blow away even immutable files. Too risky..)

It is thought to be safe because it forces the fts(3) driven descent to
only do "minimal risk" stuff. specifically, -follow is disabled, it does
checking to see that it chdir'ed to the directory it thought it was
going to, it will *not* pass a pathname with a '/' character in it to
unlink(), so it should be totally immune to symlink tree races. If it runs
into something "fishy", it bails out rather than blunder ahead.. It's better
to do that if somebody is trying to compromise security rather than risk
giving them an opportunity. Since the unlink()/rmdir() is being called
from within the current working directory during the tree descent, there
are no fork/exec overheads or races.

As a side effect of this paranoia, you cannot do a
"find /somewhere/dir -delete", as the last argument to rmdir() is
"/somewhere/dir", and the checking won't allow it. Besides, one would use
rm -rf for that case anyway. :-)

Reviewed by: pst (some time ago, but I've removed the immutable file
deletion code that he complained about since he last saw it)


# 9192bbf4 06-Apr-1996 Bruce Evans <bde@FreeBSD.org>

Use strtoq() instead of strtol() so that large inums, and sizes can be
specified.

Not fixed: specification of large uids and gids; silent truncation of
unrepresentable values.


# 81e236a0 16-Oct-1995 Garrett Wollman <wollman@FreeBSD.org>

Don't use printf() for simple strings because it is slow. Closes PR 783.

Submitted by: Wolfram Schneider <wosch@freebsd.first.gmd.de>


# e9f1a293 12-Sep-1995 Nate Williams <nate@FreeBSD.org>

Simpler fix to the find bug reported by Terry Lambert <terry@lambert.org>

[ Find to a file vs. to stdout ] produces different output because find
does not flush stdout when doing a -print.

Submitted by: Jeffrey Hsu <hsu@freefall.freebsd.org>


# 656dcd43 07-Aug-1995 Garrett Wollman <wollman@FreeBSD.org>

Delete bogus referneces to timezone code internal header file `tzfile.h',
which is no longer bogusly installed in /usr/include.


# 7799f52a 30-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


# 7cd23434 09-May-1995 Garrett Wollman <wollman@FreeBSD.org>

Add GNU-style `-print0' primary. This exists so that one can safely
do `find some-nasty-expression -print0 | perl -n0e unlink' and have all
the files actuallly get deleted. (Using `xargs' and `rm' is not safe.)


# 9b50d902 26-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Usr.bin Sources