The following script is used to clear a cache periodically:
#!/opt/homebrew/bin/bash set -xv exec &>/tmp/err xattr -rc /Users/user_id/Library/Caches/* rm -rf /Users/user_id/Library/Caches/*
When invoked from the command line, it works correctly as expected. When invoked as a cronjob, both xattr and rm commands result in "Operation not permitted" error messages.
The files in the Caches subdirectory only have the quarantine attribute attached to them and the file system is APFS (running on Sonoma).