How To Use the history Command in Linux

Linux is a command-based operating system that relies primarily on commands to execute tasks. During a terminal session, you run various commands; noting them is not feasible as it can be time-intensive. That’s why the history command is handy to view previously run commands in the terminal.

It helps you recall and reuse earlier commands and troubleshoot unexpected system behavior. So this short blog will briefly explain how to use the history command in Linux, including its usage, options, and some examples.

How To Use the history Command in Linux

You can run the below command to check the history of the previously executed commands:


The above command, by default, shows a list of up to 1,000 commands. If you wish to view a specific number of commands, go for the below command:


Where N is the required number of preceding commands. For example, to see the last 3 commands executed, we will enter:


Please combine history with the grep command to search for a particular earlier command. For instance, to search for occurrences of cd:


If you want to reuse any previous commands, please check that command’s line number. For example, let’s reuse the cd ~/Documents available in the 9th row:


If you want to clear the history, then please use the -c option:


Moreover, the ‘-d N’ option deletes a specific entry at N. For example, let’s delete the history from raw 200 to 275:

A Quick Wrap-up

The history command is a valuable tool in Linux’s range of commands. It allows you to recall and manage previously executed commands. This blog demonstrated how to use the history command with practical examples. Furthermore, we explained two primary options to manage the command history. 


Leave a Comment