如何在Android 10手机的查找命令中排除文件夹树



我有这个命令可以清除我Android 10手机上超过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:坏参数'data/cache/backup_stage',-not参数被忽略。

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

Here如何在查找中排除目录。命令

here只删除linux目录下的文件,而不是目录在其他地方我找不到解决办法。

我怎么在手机上完成这个?

我想应该是这样的。

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

最新更新