aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-06-10 12:38:43 -0700
committerRob Landley <rob@landley.net>2019-06-11 09:52:25 -0500
commit3eeda4f9293f8157d12d86e3b46d4bb4b45ab5c2 (patch)
tree36caa4f55e4451e6a9b830703d67dbb3eafe2bad
parentebc2c400763d0a2cbf092534150b3cd6744d51f9 (diff)
downloadtoybox-3eeda4f9293f8157d12d86e3b46d4bb4b45ab5c2.tar.gz
find: add -true/-false.
Used near the end of the AOSP build. Almost there! (This patch also fiddles with the help text to be able to slip the new options in without requiring so much extra space.)
-rwxr-xr-xtests/find.test3
-rw-r--r--toys/posix/find.c43
2 files changed, 27 insertions, 19 deletions
diff --git a/tests/find.test b/tests/find.test
index 26ad1626..ab84fb07 100755
--- a/tests/find.test
+++ b/tests/find.test
@@ -105,4 +105,7 @@ testing "-printf" "find dir -name file -printf '%f %p %P %s'" \
testing "-printf .N" "find dir -name file -printf %.2f" "fi" "" ""
+testing "-false" "find dir -false" "" "" ""
+testing "-true" "find dir/file -true" "dir/file\n" "" ""
+
rm -rf dir
diff --git a/toys/posix/find.c b/toys/posix/find.c
index fe712c88..5fc9b0ce 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -17,24 +17,25 @@ config FIND
usage: find [-HL] [DIR...] [<options>]
Search directories for matching files.
- Default: search "." match all -print all matches.
+ Default: search ".", match all, -print matches.
-H Follow command line symlinks -L Follow all symlinks
Match filters:
- -name PATTERN filename with wildcards -iname case insensitive -name
- -path PATTERN path name with wildcards -ipath case insensitive -path
- -user UNAME belongs to user UNAME -nouser user ID not known
- -group GROUP belongs to group GROUP -nogroup group ID not known
- -perm [-/]MODE permissions (-=min /=any) -prune ignore contents of dir
- -size N[c] 512 byte blocks (c=bytes) -xdev only this filesystem
- -links N hardlink count -atime N[u] accessed N units ago
- -ctime N[u] created N units ago -mtime N[u] modified N units ago
- -newer FILE newer mtime than FILE -mindepth # at least # dirs down
- -depth ignore contents of dir -maxdepth # at most # dirs down
- -inum N inode number N -empty empty files and dirs
- -type [bcdflps] (block, char, dir, file, symlink, pipe, socket)
- -context PATTERN security context
+ -name PATTERN filename with wildcards (-iname case insensitive)
+ -path PATTERN path name with wildcards (-ipath case insensitive)
+ -user UNAME belongs to user UNAME -nouser user ID not known
+ -group GROUP belongs to group GROUP -nogroup group ID not known
+ -perm [-/]MODE permissions (-=min /=any) -prune ignore dir contents
+ -size N[c] 512 byte blocks (c=bytes) -xdev only this filesystem
+ -links N hardlink count -atime N[u] accessed N units ago
+ -ctime N[u] created N units ago -mtime N[u] modified N units ago
+ -newer FILE newer mtime than FILE -mindepth N at least N dirs down
+ -depth ignore contents of dir -maxdepth N at most N dirs down
+ -inum N inode number N -empty empty files and dirs
+ -type [bcdflps] type is (block, char, dir, file, symlink, pipe, socket)
+ -true always true -false always false
+ -context PATTERN security context
Numbers N may be prefixed by a - (less than) or + (greater than). Units for
-Xtime are d (days, default), h (hours), m (minutes), or s (seconds).
@@ -43,11 +44,10 @@ config FIND
!, -a, -o, ( ) not, and, or, group expressions
Actions:
- -print Print match with newline -print0 Print match with null
- -exec Run command with path -execdir Run command in file's dir
- -ok Ask before exec -okdir Ask before execdir
- -delete Remove matching file/dir
- -printf FORMAT Print using format string
+ -print Print match with newline -print0 Print match with null
+ -exec Run command with path -execdir Run command in file's dir
+ -ok Ask before exec -okdir Ask before execdir
+ -delete Remove matching file/dir -printf FORMAT Print using format string
Commands substitute "{}" with matched file. End with ";" to run each file,
or "+" (next argument after "{}") to collect and run with multiple files.
@@ -305,6 +305,11 @@ static int do_find(struct dirtree *new)
} else if (!strcmp(s, "not")) {
if (check) not = !not;
continue;
+ } else if (!strcmp(s, "true")) {
+ if (check) test = 1;
+ } else if (!strcmp(s, "false")) {
+ if (check) test = 0;
+
// Mostly ignore NOP argument
} else if (!strcmp(s, "a") || !strcmp(s, "and") || !strcmp(s, "noleaf")) {
if (not) goto error;