Execute commands when you log out

From go2linux.org

I like all about automation, and who no?. How about automatically run commands when you logout from a shell session in Linux. You can use this to erase temp files you may have use during your session, or anything you may want to execute each time you logout from your Linux Operating system.

The .logout file

If you are using tcsh you can use the .logout file, where you can write all the commands you want to be executed at logout time.

This is a simple example, to erase your personal temporal files. I usually have a folder /tmp/ on my own home folder, where I save files I might need later, but I know I do not want to save forever.

## Logout File ##
rm -rf ~/tmp/*

Take care when using rm -rf

You can make more elaborated files, like erasing only files that are older than 10 days, or any other thing.

If you are using bash, the file you need to create is .bash_logout instead of .logout, or you can create a link.

I created the .logout file, and the linked it with:

ln -s .logout .bash_logout

From go2linux.org


I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....