bash_history

.bash_historyBash Command History

GNU Project · 1989

Developer
GNU Project
Category
Programming
MIME Type
text/plain
First Released
1989
Open Format
Yes
File Signature
N/A
At a Glance
.bash_history
Bash Command History

A plain text file that automatically logs every command you type in the Bash shell.

Reviewed on July 26, 2026
Compression
Plain text
Transparency
No
Editability
High
Best for
Command recall

Key Features

  • Stores a chronological record of executed shell commands.
  • Facilitates command recall and re-execution for efficiency.
  • Plain text format, easily readable and editable.
  • Configurable history size and behavior through shell variables.

Best For

  • Users who frequently work in the command line.
  • Remembering and reusing complex commands.
  • Quickly accessing past commands.
  • Basic command logging for personal reference.

Less Ideal For

  • Storing sensitive information that could be exposed.
  • Complex scripts or program code.
  • Long-term archival of operational logs.
  • Sharing of structured data or configurations.

Common Use Cases

  • Re-running complex or frequently used commands.
  • Auditing command execution for security or troubleshooting.
  • Learning from previously executed commands.
  • Sharing command snippets with others.

How to Open It

  1. Open it with any standard text editor (e.g., VS Code, Sublime Text, Nano, Vim, Emacs) on Linux, macOS, or Windows.
  2. View its contents directly in the terminal using the `cat ~/.bash_history` command.
  3. List commands with line numbers using `nl ~/.bash_history`.
  4. Search within history using `grep 'your_command' ~/.bash_history`.

What is a .bash_history file?

The .bash_history file is a simple text file that stores a log of all the commands you have executed in your Bash shell sessions. Every time you type a command and press Enter, it's typically appended to this file. This allows you to easily recall and re-execute previous commands using the up and down arrow keys or the history command, saving you time and effort when performing repetitive tasks on the command line. It's a fundamental tool for any Linux or macOS user who relies on the terminal for their workflow.

Programs That Open .bash_history Files

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

Common Problems with .bash_history Files

⚠️ History is not being saved or is too short.
Check your Bash configuration files (e.g., .bashrc, .bash_profile) for HISTSIZE and HISTFILESIZE variables. Ensure they are set to a reasonable number and that the files are being sourced correctly.
⚠️ Accidentally deleted important commands.
Restore from a backup if available, or use file recovery tools. Consider setting up more robust logging or version control for critical command sequences.
⚠️ Sensitive commands are logged.
Be mindful of what commands you execute. Use `unset HISTFILE` temporarily if you need to run commands without logging, or configure your shell to ignore specific commands from history.

Frequently Asked Questions

Where is the .bash_history file located?

It is typically found in your home directory, denoted by '~/.bash_history'.

Can I edit the .bash_history file directly?

Yes, you can edit it with any text editor. However, be cautious as incorrect edits can cause issues or data loss. It's usually better to rely on shell commands for history management.

How do I clear my bash history?

You can clear it by running `history -c` in the terminal, which clears the current session's history, and then remove the `~/.bash_history` file.

What if I use a different shell like Zsh?

Other shells like Zsh use similar history files (e.g., .zsh_history) with comparable functionality.

Technical Details

This file is a plain text document, where each line represents a single command executed in the Bash shell. It doesn't contain any special formatting or metadata beyond the command itself. The file is typically located in the user's home directory (~/.bash_history). The shell's history settings, controlled by variables like HISTFILESIZE and HISTSIZE, dictate how many commands are stored.

Did You Know?

The .bash_history file is automatically reloaded when you start a new Bash session, but you can also force a reload of the current session's history with `history -r`.
Bash can be configured to share history across multiple terminal windows in real-time using specific settings in your .bashrc file.

Security Information

The .bash_history file logs all commands, which can include passwords or sensitive information if typed directly into the terminal. Be extremely cautious about sharing this file or allowing unauthorized access to it. Consider using features like `HISTCONTROL=ignorespace` to prevent logging commands preceded by a space.

Related Extensions