Run script before logout/exit from system

Latest response

I want a script to be executed when logout is requested. I mean just execute script before actual logout happens.
My script renames old files. It is working script because i've tested it by running.
Through a lot of googling, i came to understand that ~/.bash_logout file will be edited and the command to run script will be written in it. But my linux doesn't have ~/.bash_logout file. It has only ~/.bash_profile which is executed at login. How can i run my script before logout?


Hi Narendra,

The .bash_logout file does not have to exist.

Its contents are sourced when a Bash login shell exits. The file makes it possible to run, for example, various forms of cleanup when logging out from a terminal session, as you mentioned.

So, you simply create that file in your home directory and put the commands in it as you see fit.


Dusan Baljevic (amateur radio VK2COT)