Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to make a command run every time I log out. Is there a way to do this?

share|improve this question
up vote 3 down vote accepted

If you are speaking of logging out of a bash login shell, there's a solution with ~/.bash_logout — Run man bash in the terminal for more details.

If you are speaking of logging out of the X-window system, there are far too many ways to get yourself "logged out" for there to be any way to guarantee the command will run.

However, since you are the one doing the logging out, if you change your logout habit, this might work...

If you are running gnome, you might want to write a short script - maybe called "logo" - put it in ~/bin (and ensure ~/bin is in your PATH).

The "logo" script would do two things:

  1. Run whatever command you want to run when you logout.
  2. Run gnome-session-save with your choice of arguments.

Run man gnome-session-save in the terminal for more details on the arguments.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.