Linux history command

To check the command run on any terminal  the command used is "history"


#history

Sample output

$ history
    6  tracerout 10.19.250.181
    7  traceroute 10.19.250.181
    8  ping 10.220.196.64
    9  traceroute [oracle@ITPFEBPAS0816P ~]$ ping 10.220.196.64
   10  PING 10.220.196.64 (10.220.196.64) 56(84) bytes of data.
   11  10.220.196.6
   12  traceroute 10.220.196.64
   13  ping 210.31.24
   14  ping 10.210.31.24
   15  ping 10.210.31.16
   16  ping 10.220.196.45
   17  ping 10.220.196.14

To repeat the 12 the command

#!12

In the above history is not displaying the time stamp .. To get the time stamp

# HISTTIMEFORMAT="%d/%m/%y %T "
# history

$ history
   10  07/09/15 14:16:19 PING 10.220.196.64 (10.220.196.64) 56(84) bytes of data.
   11  07/09/15 14:16:19 10.220.196.6
   12  07/09/15 14:16:19 traceroute 10.220.196.64
   13  07/09/15 14:16:19 ping 210.31.24
   14  07/09/15 14:16:19 ping 10.210.31.24
   15  07/09/15 14:16:19 ping 10.210.31.16
   16  07/09/15 14:16:19 ping 10.220.196.45
   17  07/09/15 14:16:19 ping 10.220.196.14
   18  07/09/15 14:16:19 traceroute 10.220.196.14


#to make the above commands work permanently

$ ls -lart .bash*
-rw-r--r--. 1 oracle oinstall   124 Jan 27  2011 .bashrc
-rw-r--r--. 1 oracle oinstall    18 Jan 27  2011 .bash_logout
-rw-r--r--. 1 oracle oinstall   828 Feb 25  2015 .bash_profile
-rw-------. 1 oracle oinstall 16837 Sep  2 10:39 .bash_history

#to make the above commands work permanently add the below line to   .bash_profile

export HISTTIMEFORMAT="%d/%m/%y %T "

Explanation of commands and switches.
  1. history – GNU History Library
  2. HISTIMEFORMAT – Environmental Variable
  3. %d – Day
  4. %m – Month
  5. %y – Year
  6. %T – Time Stamp


 

Post a Comment

And that's all there is to it!

If anyone has any other questions or requests for future How To posts, you can either ask them in the comments or email me. Please don't feel shy at all!

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

Previous Post Next Post