Continuously clearing the cache of a long-running non-configurable process
If you have a long-running process which produces too much cache (or log) output which you don’t need, and the process can not be configured to turn this off, here is how to delete the files as soon as they are created.
-
Install inotify-tools. On debian package is inotify-tools
- Create a script to watch and delete the files:
#!/bin/bash DIR="/my/cache/dir" inotifywait -m -r -e close_write "$DIR" --format "%f" | while read f do echo $f rm $DIR/$f done
This is adapted from this StackOverflow. Note the use of the
close_write
event. - Run the script in background:
.\myscript &
This approach is efficient in that there does not need to be a poll loop and the files are deleted only once they have been closed after writing.