Automatic File Cleanup

If you use a system to make temporary files (), your logout file can clean up the temporary files. The exact cleanup command you'll use depends on how you create the files, of course. The overall setup looks something like this in logout:

~ 
(set nonomatch; cd ~/temp && rm -f *) &

The parentheses run the commands in a subshell () so the cd command won't change the current shell's working directory. The C shell needs a set nonomatch () command so the shell will be quiet if there aren't any temp files to clean up; omit that command in Bourne-type shells. The && () means that rm won't run unless the cd succeeds. Using cd ~/temp first, instead of just rm ~/temp/*, helps to keep rm's command-line arguments from getting too long () if there are lots of temporary files to remove.

If you could be logged in more than once, be careful not to remove temp files that other login sessions might still be using. One way to do this is with the find () command - only remove files that haven't been modified in the last day:

xargs 
find ~/temp -type f -mtime +1 | xargs rm -f &

- JP