Sté*_*las 11
-mtime是find(与-delete)的标准谓词,但看起来您有一个精简版的busybox,其中该FEATURE_FIND_MTIME功能已在构建时被禁用。
如果您可以在启用busybox的情况下重建它,您应该能够:
find . -mtime +6 -type f -exec rm -f {} +
Run Code Online (Sandbox Code Playgroud)
或者如果FEATURE_FIND_DELETE也启用:
find . -mtime +6 -type f -delete
Run Code Online (Sandbox Code Playgroud)
如果没有,其他选项可能是在设置为具有一周旧修改时间的文件上使用find -newer(假设FEATURE_FIND_NEWER已启用)。
touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -newer ../ref -exec rm -f {} +
Run Code Online (Sandbox Code Playgroud)
或者,如果-newer不可用,但sh的[支持-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
Run Code Online (Sandbox Code Playgroud)