Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to View Your Bash History

This guide explains what bash history is and how to read it, search it and clear it.

How-To Guides2 min read6 steps

What is bash history?

Bash is the program that reads the commands you type in a Linux terminal. A terminal is a window where you type instructions to the server. Bash keeps a list of the commands you ran before. That list is the history. It is like the history list in a web browser. It helps you repeat old commands and see what happened on a server.

The list is saved in a hidden file called .bash_history in your home folder. Each user has their own.

Steps to view it

  1. Connect to your server with SSH, or open the terminal.
  2. Type this and press Enter:
history

This prints your past commands with a number beside each one.

  1. To see only the last 20, type:
history 20
  1. To search for a word, such as nano:
history | grep nano

The | sign passes the list to grep, which keeps only the lines that match.

Handy shortcuts

  • Press the Up arrow to bring back the last command.
  • Press Ctrl + R and type a few letters to search old commands.
  • Type !42 to run command number 42 again.
  • Type !! to run the last command again.

Show the time of each command

  1. Run this:
export HISTTIMEFORMAT="%F %T "

This adds a date and time to each line shown from now on.

  1. Run history again.

Reviewing another user's history

If you have root access, you can read another user's file. Replace username with theirs:

cat /home/username/.bash_history

This helps when you check for strange activity on a server.

Clearing history

Warning: this deletes the list for good.

history -c

This clears the list in your current session. The saved file may still hold old lines. Deleting it with rm ~/.bash_history removes those too.

Tip: Never type passwords in a command line. They would stay in the history file.

Quick recap

  • Bash history is a list of commands you ran.
  • Type history to see it.
  • Use grep or Ctrl + R to search it.
  • It is stored in ~/.bash_history.