aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-08-04 19:28:41 -0500
committerRob Landley <rob@landley.net>2014-08-04 19:28:41 -0500
commit4edcd084f4782518249b888efc5d8f965bd5742e (patch)
tree0ced0c1adc4aa350e82913a97b4c8c3ba5c22650 /toys/posix
parent60c35c486a2ea1c6ea8920c599abf992b27542c5 (diff)
downloadtoybox-4edcd084f4782518249b888efc5d8f965bd5742e.tar.gz
find.c: add -mindepth, -maxdepth, and document -newer and -depth.
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/find.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/toys/posix/find.c b/toys/posix/find.c
index dedf3ede..6b434c1e 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -22,14 +22,16 @@ config FIND
-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 -nouser belongs to unknown user
- -group GROUP belongs to group -nogroup belongs to unknown group
- -perm [-]MODE permissons (-=at least) -prune ignore contents of dir
- -size N[c] 512 byte blocks (c=bytes) -xdev stay in this filesystem
- -links N hardlink count -atime N accessed N days ago
- -ctime N created N days ago -mtime N modified N days ago
+ -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 not in /etc/passwd
+ -group GROUP belongs to group GROUP -nogroup group not in /etc/group
+ -perm [-]MODE permissons (-=at least) -prune ignore contents of dir
+ -size N[c] 512 byte blocks (c=bytes) -xdev stay in this filesystem
+ -links N hardlink count -atime N accessed N days ago
+ -ctime N created N days ago -mtime N modified N days ago
+ -newer FILE newer mtime than FILE -mindepth # at least # dirs down
+ -depth ignore contents of dir -maxdepth # at most # dirs down
-type [bcdflps] (block, char, dir, file, symlink, pipe, socket)
Numbers N may be prefixed by a - (less than) or + (greater than):
@@ -322,6 +324,15 @@ static int do_find(struct dirtree *new)
test = compare_numsign(new->st.st_size, 512, ss[1]);
} else if (!strcmp(s, "links")) {
if (check) test = compare_numsign(new->st.st_nlink, 0, ss[1]);
+ } else if (!strcmp(s, "mindepth") || !strcmp(s, "maxdepth")) {
+ if (check) {
+ struct dirtree *dt = new;
+ int i = 0, d = atolx(ss[1]);
+
+ while ((dt = dt->parent)) i++;
+
+ test = s[1] == 'i' ? i >= d : i <= d;
+ }
} else if (!strcmp(s, "user") || !strcmp(s, "group")
|| !strcmp(s, "newer"))
{