home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 3.3 Electronic Fortune Cookies Chapter 3
Logging Out
Next: 3.5 Stop Accidental C Shell Logouts
 

3.4 Automatic File Cleanup

If you use a system to make temporary files ( 21.3 ) , 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 ( 13.7 ) so the cd command won't change the current shell's working directory. The C shell needs a set nonomatch ( 15.4 ) 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 && ( 44.9 ) 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 ( 15.6 ) 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 ( 17.2 ) command - only remove files that haven't been modified in the last day:



xargs
 

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

- JP


Previous: 3.3 Electronic Fortune Cookies UNIX Power Tools Next: 3.5 Stop Accidental C Shell Logouts
3.3 Electronic Fortune Cookies Book Index 3.5 Stop Accidental C Shell Logouts

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru