如何从 Android 10 phone 上的查找命令中排除文件夹树

How to exclude a folder tree from find command on an Android 10 phone

我有这个命令可以清除我 Android 10 phone:

上所有应用程序超过 3 天的缓存文件
find /data/data/*/cache -type f -mtime +3 -exec rm -r {} +

现在我想排除文件夹 /data/data/org.fdroid.fdroid/cache 及其子文件夹。我遇到两个问题

  1. 要排除的文件夹路径在find命令的根路径下 所以这不起作用(不排除)

find /data/data/*/cache -type f -not \( -name org.fdroid.fdroid \) -print

(用于 -print 的测试目的)

  1. 当我将根路径减少到 /data/data 并尝试使用 -path-name 参数时,例如

find /data/data -path */cache/* -type f -not \( -name org.fdroid.fdroid \) -print

我收到诸如

之类的错误

find: bad arg 'data/cache/backup_stage' and the -not argument is ignored.

这意味着 find 不是从命令中定义的根路径开始,而是从 phone / 的根路径开始,这与我根据我发现的所有描述所期望的相反。

这里How to exclude a directory in find . command

此处Remove only files in directory on linux NOT directories 在其他地方我没有找到解决方案。

如何在我的 phone 上完成此操作?

我觉得是这样的。

find /data/data/*/cache -type f -not -path '/data/data/org.fdroid.fdroid/*' -mtime +3 -delete

或者

find /data/data/*/cache -type f -not -path '/data/data/org.fdroid.fdroid/cache/*' -mtime +3 -delete