Important 'History' Commands | RHEL7 Linux

most useful history commands in linux redhat ubuntu

Some History Commands That You Have To Know.

1) To show time & date in your history commands, run below command before run history command.


give space before ending comma at last so it will be more visible

2) To ignore common simple commands(like ls,clear,pwd etc) from history to focus on only important commands.

#export HISTIGNORE="pwd:ls -l:date:clear:ll:"

3) Ignore spaces in list of commands shown in history.

#export HISTCONTROL=ignorespace

4) Ignore repeated commands in sequence which shows in history.

#export HISTCONTROL=ignoredups 

This will ignore commands which you run multiple is same time.

5) To make these above commands permanent just add them to user's '.bash_profile'  file and these commands will be permanent.

#vim .bash_profile


Add line in '.bash_profile' file

6)To undo  any history setting.

#unset export HISTCONTROL

7) To see only last 20 commands

#history 20

8) Use of Bang (!) sign in to execute the n number of command in history list.


Where n in a positive number

9) Use of Bang (!) with character string of command to execute/print the latest matching string command


This will print/execute the recent used cat command.

10) Use of Bang Bang (!!) sign will repeat the last executed command


11) Press ctrl+r and enable reverse-i-search & type any command's starting words. This will search the command start with matching input & hit enter.

history commands in linux

12) Remove All History

#history -c

13)  Remove a single command with entry number in history list

#history -d 1021

This will remove the 1021 number command in history list

Sharing is Caring 😊

Post a Comment