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

Time:04-25

I have this command that works to clear the cache files older than 3 days of all apps on my Android 10 phone:

find /data/data/*/cache -type f -mtime  3 -exec rm -r {}  

Now I want to exclude the folder /data/data/org.fdroid.fdroid/cache and its subfolders. I encounter two problems

  1. the folder path to be excluded is below the root path of the find command So this does not work (nothing excluded)

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

(for test purposes with -print)

  1. When I reduce the root path to /data/data and try to work with -path and -name arguments such as

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

I get errors such as

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

This means find does not start at the root path defined in the command but at root of the phone / contrary to what I expect according to all descriptions I found.

Here How to exclude a directory in find . command

here Remove only files in directory on linux NOT directories and in other places I didn't find a solution.

How can I accomplish this on my phone?

CodePudding user response:

Something like this I think.

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

Or

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