Finding files older than x days on a system with a stripped down busybox
-mtime
is a standard predicate of find
(contrary to -delete
) but it looks like you have a stripped down version of busybox
, where the FEATURE_FIND_MTIME
feature has been disabled at build time.
If you can rebuild busybox with it enabled, you should be able to do:
find . -mtime +6 -type f -exec rm -f {} +
Or if FEATURE_FIND_DELETE
is also enabled:
find . -mtime +6 -type f -delete
If not, other options could be to use find -newer
(assuming FEATURE_FIND_NEWER
is enabled) on a file that is set to have a one week old modification time.
touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -newer ../ref -exec rm -f {} +
Or if -newer
is not available but sh
's [
supports -nt
:
touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -exec sh -c '
for f do
[ "$f" -nt ../ref ] || printf "%s\0" "$f"
done' sh {} + |
xargs -0 rm -f
From man find
:
-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.
-ctime n
File's status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file status change times.
Depending on the use cases of the files you want to delete, these are your only other options for find
. Why is mtime
not available? What filesystem are you using? Did you explore any other options?