From 3eeda4f9293f8157d12d86e3b46d4bb4b45ab5c2 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 10 Jun 2019 12:38:43 -0700 Subject: 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.) --- toys/posix/find.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'toys/posix') 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...] [] 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; -- cgit v1.2.3