The command
Here's what you're looking for:
for file in /home/hussam/.cache/someapp/Tempfiles-*; do [[ $(lsof | grep "$file") ]] || /usr/bin/rm "$file"; done
Don't use
rm -rf. If there's an issue and it fails, you don't want it to follow through. Be defensive, not aggressive.
If you want to use
find instead, use the
-delete argument.
Cron
Adding this to your crontab is pretty straightforward. I generally recommend going through a file on disk. Something like this:
$ crontab -l > my_crontab
$ echo '0 21 * * * my_super_command' >> my_crontab # this will execute my_super_command every day at 21:00.
$ crontab my_crontab
Every time you want to modify the crontab, modify the
my_crontab file and update it like this.
Caution
Seriously though, be careful with these commands. I wouldn't feel comfortable having something that deletes files in my cron. If you want to be extra safe, tweak this command to have a
--dry-run option that will simply list the files it'd delete. Run it for a week or two and once you're confident it's not doing anything wrong, turn the real delete on.