How to use history command in Linux

Running history command lets you view previously run commands in terminal. Below is output of history command in Fedora. The output shows a list of commands with a number before each command.


The numbers  shown in above command can be used to run any command from list of output of history. Like if I want to run command number 6 I will simply type !6.

There is another method to run old command from history. Just type exclamation mark followed by few alphabets of command you want to run – !l. Only disadvantage of these two methods is command will directly run command without asking for any confirmation.

These commands have been used in Fedora and Redhat Linux  Different version may show different output.