Main menu

Linux History Command

Linux history command is used to listing all the commands run by current logged in user. History is a feature of BASH shell.

List all your history

[zoladius@localhost]$history

List history and filter using grep

[zoladius@localhost]$history | grep yum

Clear you command history

[zoladius@localhost]$history -c

Checking your history file in your home folder

[zoladius@localhost~]#cat .bash_history


History environment variables

View history with date and time : Set HISTTIMEFORMAT variable where %F is for date and %T for time. I don’t know why they used %F for time. Your also can use different separator like blank space, dashes and so on.

[zoladius@localhost]$HISTTIMEFORMAT='%F -- %T -- '
1006  2014-08-01 -- 01:20:48 -- history
1007  2014-08-01 -- 01:20:52 -- export HISTTIMEFORMAT='%F %T'
1008  2014-08-01 -- 01:20:55 -- history
1009  2014-08-01 -- 01:21:03 -- export HISTTIMEFORMAT='%F %T -- '
1010  2014-08-01 -- 01:21:04 -- history
1011  2014-08-01 -- 01:21:15 -- export HISTTIMEFORMAT='%F -- %T -- '
1012  2014-08-01 -- 01:21:16 -- history

Ignore duplicate commands in history

[zoladius@localhost]$HISTCONTROL=ignoredups

Ignore specific commands in history

[zoladius@localhost]$HISTIGNORE='ls -l:fdisk-l:cd:'

Disabling the history

[zoladius@localhost]$HISTSIZE=0

Saving your environment variable in your profile
[zoladius@localhost ]cd ~
[zoladius@localhost ~]$vi .bash_profile

.bash_profile

#
...
export HISTCONTROL=ignoredups


 

Navigating in your history : Use shortcuts for using your history command.

Load Previous command ^p
Load Next command ^n
Run Previous command !!
Run from command number !n
Run last command starting with string !string
Run last command having string !?string
FacebookTwitterGoogle+RSS