Using the history command

  • Applies to: Grid
    • Difficulty: Easy
    • Time Needed: 10
    • Tools Required: SSH
  • Applies to: DV
    • Difficulty: Easy
    • Time Needed: 10
    • Tools Required: SSH
  • Applies to: (ve)
    • Difficulty: Easy
    • Time Needed: 10
    • Tools Required: SSH


All of our services are currently running on Linux. In Linux, there is a very useful command to show you all of the last commands that have been recently used. The command is simply called history, but can also be accessed by looking at your .bash_history in your home folder. By default, the history command will show you the last five hundred commands you have entered.


Before you start, you'll need:


First, connect to your server via SSH.


Let's start with the simple command:


You should now see a list quickly go by with the last 500 commands used, like the example below. If you like, you can just use the up arrow and down arrow to browse for any particular command you may have used recently.

496  ls -la
497  ls
498  history
499  ls
500  cd domains
501  cd ..
502  ls
503  history
504  cd ls
505  ls
506  cd data
507  ls
508  cd ..
509  cd domains
510  ls
511  cd ..
512  history

More ways to use the command

If you wish to view the history one page at a time, you can use the command below. Now, you can simply use the spacebar to view one page at a time or use the down arrow to view one line at a time:

history | less

To view just the last ten commands, you can use the following:

history | tail

To view the last 25 commands, just use the following:

history 25

Another tool you can use with history is Ctrl + R. This will output a search feature. Just begin typing a command and it will complete the command with the most recent match. If it is not the one you need, simply type a few more letters until you find the command you wanted. Once you find it, simply press the return key to run or press the right arrow key to edit it.

Another way to search history is with the following command (just be sure to replace "searchterm"):

history | grep -i searchterm | less

As you can see, the history command can be very useful in finding the last commands that have been used on your (mt) Media Temple service.