I want to run a command, say touch ~/test.txt every time I'm logging out from my computer. Is that possible, and if so how should I go about doing this? I've looked at other responses but they were a bit too obscure. Specifically one mentioned that I should be finding some sort of 'common' file if I want this command to run for all user logout events. Any help is welcome, thanks ahead of time.
If you mean "logging out" as closing GUI session..
Depends what GUI you use:
Gnome: The script
/etc/gdm/PostSession/Default is run by root whenever someone quits his X session.
Unity (Ubuntu default): in
below a chapter of
session-cleanup-script=/path/to/your-script.sh will do the trick.
KDE will run
If you aren't talking about the GUI, it depends on your shell:
bash has a ~/.bash_logout file that gets executed when a login shell closes.
zsh has a .zlogout (in your home or in the $ZDOTDIR directory).
You can put pretty much anything in either and have it run when you log out.