Commit Graph

20 Commits

Author SHA1 Message Date
Warner Losh
46b993ff99 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.
2008-02-23 16:29:04 +00:00
Kirill Ponomarev
22170420ec 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
2006-05-14 20:23:01 +00:00
Ceri Davies
31d534254e 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
2006-04-03 20:36:37 +00:00
Oliver Eikemeier
1c8329632e - 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
2004-05-28 17:17:15 +00:00
Tim J. Robbins
5e25d888a8 Support the SysV-style -exec utility args.. {} + function, required by
SUSv3. This is similar to find foo -print0 | xargs -0 utility args.
2002-06-02 12:57:41 +00:00
Mark Murray
ecca1f1c0a Remove __P(). 2002-03-20 10:32:05 +00:00
David Malone
e98080b1e6 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.
2002-02-27 17:57:00 +00:00
Ruslan Ermilov
adff4fca3d 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
2001-09-14 12:47:13 +00:00
Ruslan Ermilov
7fd5ee41e3 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
2001-09-04 16:09:01 +00:00
Poul-Henning Kamp
ea92232a82 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>
2001-05-03 18:05:35 +00:00
Akinori MUSHA
7c1d4b3ae9 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
2001-02-23 16:20:55 +00:00
Peter Wemm
ed1a4621a2 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
2001-01-23 11:16:50 +00:00
Ollivier Robert
c76bc8f3bf 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>
2000-06-12 11:12:41 +00:00
Ollivier Robert
9d2796c3ec 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>
2000-06-12 10:36:52 +00:00
Ollivier Robert
567664c4a7 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>
1999-12-19 15:43:19 +00:00
Wolfram Schneider
3f5223f84a Add the primaries -mmin, -amin, -cmin to find, similar to the GNU find. 1997-10-13 21:06:22 +00:00
Warner Losh
127d7563c4 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
1997-08-29 23:09:45 +00:00
Peter Wemm
abacbbbf01 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)
1996-10-04 12:54:07 +00:00
Garrett Wollman
7cd23434fe 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.)
1995-05-09 19:02:06 +00:00
Rodney W. Grimes
9b50d90275 BSD 4.4 Lite Usr.bin Sources 1994-05-27 12:33:43 +00:00