I have this little command that delete all files within ~/Library/Cache, ~/Library/Logs, /Library/Cache and /Library/Logs directories but sometimes, one or more directories are missing and the rm -rf command is not execute.
sudo find ~/Library/Caches ~/Library/Logs /Library/Caches /Library/Logs -mindepth 1 -type f -exec rm -rf {}+
I wanted the command to ignore missing directories and just execute the command to the files that are found.
The only issue here is that you are annoyed with seeing the error message about missing directories.
You may redirect the standard error stream to /dev/null to ignore errors:
sudo find ~/Library/Caches ~/Library/Logs \
/Library/Caches /Library/Logs \
-mindepth 1 -type f -exec rm -rf {} + 2>/dev/null
Also note that -mindepth 1 is not needed here, and that some find implementations have -delete:
sudo find ~/Library/Caches ~/Library/Logs \
/Library/Caches /Library/Logs \
-type f -delete 2>/dev/null
Or, with a shell that understands brace expansions:
sudo find {~,}/Library/{Logs,Caches} -type f -delete 2>/dev/null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With