In Unix, how can I get a command to execute when I log out?

If you use the csh, tcsh, or bash shell, you can create a file in your home directory that contains commands that you want executed when you log off (i.e., immediately after you enter exit or logout).

If you use csh or tcsh, create a file called .logout. If you use bash, create a file called .bash_logout. In the file, put the commands you wish to have executed upon logging out.

Use this feature with care. If your .logout file is lengthy or contains errors and you leave a public terminal before verifying that the file is done executing, an unscrupulous user could gain access to your account by interrupting its execution.

Note:
This function is distinct from cron, which can perform actions at particular dates and times while you are logged out.

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document aazv in the Knowledge Base.
Last modified on 2017-05-16 11:50:47.

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.