Linux Shell History Introduction

‘history’ command will display a list of last used command in the shell on your system.

Sample syntax of :

# history <number>  

Like example of :

# history 10  

See your terminal after run the command, we have used history -10 . You can use any integer command.

It displays list of last ten commands.

history -c this command can clear your history which command you are run your terminal.

Ctrl + r

‘ctrl+r’ is executes the last command from history matching the specified characters that you type on your terminal.

Sample syntax of :

press 'ctrl+r'. <characters>  

Like example of :

press 'ctrl+r'. ca  

See your terminal after run the command, we have pressed ‘ctrl + r’ followed by two characters ca and it has found the last command matching characters ‘ca’. It is very helpful.

Linux Shell History Commands

Interacting with terminal, you will be typing some commands very often and sometimes typing with variations on those commands.

Sometimes it can be very irritating as well as a little bit time consuming.

Bash shell provides some commands to repeat the history of the commands used. The shell makes it easy for us to repeat the commands we have used.

Shell History Search Command

!!

Repeats last typed command.

!

Repeat other commands are other than last typed command.
history Shows a list of older commands.

!n

Repeats the command at line number n.

Ctrl -r

Repeats the mentioned command.

$HISTSIZE

Determines number of commnds stored in the history.

$HISTFILE

Displays location of file that contain histoty.

$HISTFILESIZE

To set number of commands stored in history file

Keys In History Command:

UP arrow key : It will scroll you backwards in history.
ctrl + p : It will scroll you backwards in history.
DOWN arrow key : It will scroll you downwards in history.
ctrl + n : It will scroll you downwards in history.
trl + r : It will take you to the command including the specified character.
ctrl + g : It means escape from history searching mode.

If you understand this article, then you can practice your own ability.