我有这个命令可以清除我Android 10手机上超过3天的所有应用程序的缓存文件:
find /data/data/*/cache -type f -mtime +3 -exec rm -r {} +
现在我想要排除文件夹/data/data/org.fdroid.fdroid/cache
及其子文件夹。我遇到两个问题
- 要排除的文件夹路径在find命令的根路径以下所以这不起作用(没有排除)
find /data/data/*/cache -type f -not ( -name org.fdroid.fdroid ) -print
(用于-print
的测试目的)
- 当我将根路径减少到
/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