Premium lesson

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 UP key will make you browse the history backwards.

  • Pressing the DOWN key will make you browse the history forwards.

Once you've found the command you want to re-run, you can either:

  1. Press the ENTER key to execute it.

  2. Press the CTRL + C key combination to cancel this command and get a new prompt without having to erasing the whole line.

icon light bulb key

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
Unlock this module