=== Logout as a User on Ubuntu The system will auto run //~/.bash_logout// after logout from the login shell, which includes, for example, ssh login. But if you log out locally in gnome-session, it won't auto run //~/.bash_logout//. However, you can add the following code into your // /etc/gdm/~PostSession/Default// file: {{{ logoutscript="$HOME/.bash_logout"; if [ -e "$logoutscript" ] then if [ -x "$logoutscript" ] then su $USER -c "$logoutscript" fi fi }}} In order to let all of this run successfully, you should do the following test first. ==== Testing For testing, you may just add {{{ echo "$USER Love You" >>$HOME/tmp }}} into your //~/.bash_logout// file for better understanding and quick test. Test the ///etc/gdm/~PostSession/Default// file can run correctly: {{{ cd /etc/gdm/PostSession ./Default }}} You may ask to type your password. If no error message displays, you are done, and you can add any command in your //~/.bash_logout// file. === Exit a terminal ==== On Mac You can edit or add //.bash_logout// file, when you exit from a terminal, the command in //.bash_logout// will auto run. ==== On Ubuntu Open one terminal, and then goto the //Edit/Profile Preferences//, and choose the //title and command// panel, check the //Run command as a login shell// box, then restart the terminal and finally exit the terminal, your //.bash_logout// will auto run.