.bash_logout — Bash Logout Script
GNU Project · 1989
A .bash_logout file is a script that runs automatically when you log out of a Bash shell session to perform cleanup or logging actions.
Key Features
- Automatic execution upon Bash logout.
- Allows for custom cleanup and logging routines.
- Scriptable with standard Bash commands.
- Located in the user's home directory for individual customization.
Best For
- Automating repetitive cleanup tasks upon logout.
- Implementing custom session termination procedures.
- System administrators managing user environments.
- Developers needing to capture session-end data.
Less Ideal For
- Executing commands at login (use .bash_profile or .bashrc).
- Storing sensitive information directly (use secure methods).
- Complex graphical user interface interactions.
- Scripts that need to run independently of a Bash session.
Common Use Cases
- Deleting temporary files created during the session.
- Logging session duration or activity.
- Saving user-specific session data.
- Closing network connections or releasing resources.
- Displaying a final message before logout.
How to Open It
- Open any text editor (like VS Code, Sublime Text, nano, vim).
- Navigate to your home directory (~).
- Locate and open the .bash_logout file.
- Edit the commands within the file and save it.
What is a .bash_logout file?
The .bash_logout file is a shell script that is automatically executed by the Bash (Bourne Again SHell) interpreter when a user logs out of a system. It's typically used to perform cleanup tasks or log out specific activities. For instance, you might use it to automatically delete temporary files, save session information, or send a notification before the session terminates. This script allows for personalized actions to be taken reliably upon exiting a Bash session.
Programs That Open .bash_logout Files
| Platform | Program | ||
|---|---|---|---|
| Windows | Windows Subsystem for Linux (WSL) | Free | Official |
| macOS | Terminal | Free | Official |
| Linux | Bash Shell | Free | Official |
Common Problems with .bash_logout Files
Frequently Asked Questions
.bash_profile is executed for login shells, .bashrc for interactive non-login shells, and .bash_logout is executed specifically when a user logs out of a Bash session.
No, it's not mandatory. It's an optional file for customizing logout behavior. If it doesn't exist, Bash will simply log you out without running any custom script.
Yes, you can include any valid Bash command. However, be cautious with commands that might cause issues or prevent a clean logout.
Technical Details
This file is a plain text file containing Bash shell commands. When a user logs out, Bash checks for the existence of this file in the user's home directory and executes its contents. The commands within .bash_logout are interpreted sequentially by the Bash interpreter.