Linux History Command Time stamp Search clear Command


Bash revember what command we are receantly executed.Using History command we can  list out that  previous command or recently executed command.

View Time Stamp Of The Command
bash @script # export HISTTIMEFORMAT='%F %T '
It will list out command with timestamps
bash @script #history
   26   2010-05-05 16:04:08 /etc/init.d/networking restart
   27   2010-05-05 16:04:24 service networking restart
   28   2010-05-05 16:04:55 find / -name iptable*
   29   2010-05-05 16:11:27 /sbin/iptables-save
   30   2010-05-05 16:11:33 service networking restart
if you need to reset as per pervious Format
bash @script # export HISTTIMEFORMAT=''
Search Command History
using shortcut - Hot Key
Ctrl+R -search command history
bash @script #
(reverse-i-search)`find': find / -name bash_profile*

How To Save The Linux History Command Into Separate File
#history >> file.txt
it will save the history of command into the file.txt file.

How to Executed Previous Command
Method 1) !! Execute the previous command
[root@localhost home]# !!
aquota.user  lost+found  user1
Here ls is previous executed command

Method 2) [root@localhost home]# !331 >> (#dir is the 331 command)dir
aquota.user  lost+found  user1
Method 3) [root@localhost home]# !c >>(command start with character c )
cd /
Method 4) use the up and Down arrow we can run currently executed command
Clear The History command
After you finished any configuration if you need to clear the history command For maintaince security purpose.
[root@localhost etc]# history -c

How to Set History Limit using .bash_profile
If you like to set any Limit in history example if user only see the last
10 command in every time meang you can edit .bash_profile. I clearly expalain about these article from the following linkHISTORY COMMAND PERSONAL SETTING FILELimit no of command

No comments:
Write comments