The Command History
Shell·3 min read·Jan 1, 2025
Just like your web browser saves the searches you perform, the shell keeps an internal history of all the commands you execute, allowing you to easily re-run them in the future.
In Bash, the command history is saved in a text file named .bash_history and is located in your home directory, which is /home/username on Linux and /Users/username on macOS.
Browsing through the history
The easiest way to browse through the list of commands saved in your shell history is to use the UP and DOWN arrow keys of your keyboard, where:
-
Pressing the
UPkey will make you browse the history backwards. -
Pressing the
DOWNkey will make you browse the history forwards.
Once you've found the command you want to re-run, you can either:
-
Press the
ENTERkey to execute it. -
Press the
CTRL + Ckey combination to cancel this command and get a new prompt without having to erasing the whole line.
Unlock the CLI & Scripting with Bash module
Learn how to gain advanced control over the OS and automate complex routine tasks prone to manual errors with the CLI and Bash scripting.
You get immediate access to:
- 34 focused lessons across the CLI and Bash
- 4 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle