bash_logout

.bash_logoutBash Logout Script

GNU Project · 1989

Developer
GNU Project
Category
Programming
MIME Type
application/x-shellscript
First Released
1989
Open Format
Yes
File Signature
N/A
At a Glance
.bash_logout
Bash Logout Script

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.

Reviewed on July 26, 2026
Compression
Plain text
Transparency
N/A
Editability
High
Best for
Automated logout 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

  1. Open any text editor (like VS Code, Sublime Text, nano, vim).
  2. Navigate to your home directory (~).
  3. Locate and open the .bash_logout file.
  4. 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

PlatformProgram
WindowsWindows Subsystem for Linux (WSL)FreeOfficial
macOSTerminalFreeOfficial
LinuxBash ShellFreeOfficial

Common Problems with .bash_logout Files

⚠️ Script errors preventing logout.
Carefully review the script for syntax errors or problematic commands. Test commands individually in a terminal before adding them to .bash_logout.
⚠️ Script not running.
Ensure the file is named exactly '.bash_logout' (with the leading dot) and is located in the user's home directory. Verify file permissions allow execution, though Bash typically handles this for scripts in home directories.

Frequently Asked Questions

What is the difference between .bash_logout, .bashrc, and .bash_profile?

.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.

Do I need a .bash_logout file?

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.

Can I put any Bash command in .bash_logout?

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.

Did You Know?

The leading dot in '.bash_logout' makes it a hidden file in most Unix-like file managers.
It's part of the standard Bash configuration mechanism, executed by the 'logout' shell builtin.

Security Information

Be cautious when adding commands to .bash_logout. Ensure scripts are well-tested to avoid unintended side effects or security vulnerabilities. Do not store sensitive credentials or commands that could compromise system security.

Related Extensions