aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-12-20 16:40:38 -0600
committerRob Landley <rob@landley.net>2016-12-20 16:40:38 -0600
commit86aca0458598bf68f3264b70b0eddb19ece7edd3 (patch)
tree55b95cba50924b156b945889fd396cd7b9e11897 /toys
parent1b738848d0999a48164da1ae614b4ecb4024feef (diff)
downloadtoybox-86aca0458598bf68f3264b70b0eddb19ece7edd3.tar.gz
Add units for -atime and friends. (Also legacy -amin alias, but not in help text
because there's no -asec or -ahour.)
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/find.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/toys/posix/find.c b/toys/posix/find.c
index 86fc141f..5c72131d 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -30,14 +30,15 @@ config FIND
-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 accessed N days ago
- -ctime N created N days ago -mtime N modified N days ago
+ -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)
- Numbers N may be prefixed by a - (less than) or + (greater than):
+ 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).
Combine matches with:
!, -a, -o, ( ) not, and, or, group expressions
@@ -350,15 +351,23 @@ static int do_find(struct dirtree *new)
if ((new->st.st_mode & S_IFMT) != types[i]) test = 0;
}
- } else if (!strcmp(s, "atime")) {
- if (check)
- test = compare_numsign(TT.now - new->st.st_atime, 86400, ss[1]);
- } else if (!strcmp(s, "ctime")) {
- if (check)
- test = compare_numsign(TT.now - new->st.st_ctime, 86400, ss[1]);
- } else if (!strcmp(s, "mtime")) {
- if (check)
- test = compare_numsign(TT.now - new->st.st_mtime, 86400, ss[1]);
+ } else if (strchr("acm", *s)
+ && (!strcmp(s+1, "time") || !strcmp(s+1, "min")))
+ {
+ if (check) {
+ char *copy = ss[1];
+ time_t thyme = (int []){new->st.st_atime, new->st.st_ctime,
+ new->st.st_mtime}[stridx("acm", *s)];
+ int len = strlen(copy), uu, units = (s[1]=='m') ? 60 : 86400;
+
+ if (len && -1!=(uu = stridx("dhms",tolower(copy[len-1])))) {
+ copy = xstrdup(copy);
+ copy[--len] = 0;
+ units = (int []){86400, 3600, 60, 1}[uu];
+ }
+ test = compare_numsign(TT.now - thyme, units, copy);
+ if (copy != ss[1]) free(copy);
+ }
} else if (!strcmp(s, "size")) {
if (check)
test = compare_numsign(new->st.st_size, 512, ss[1]);