LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-27-2012, 12:49 AM   #1
JATA01
Member
 
Registered: Nov 2007
Posts: 207

Rep: Reputation: 15
Question Bash History: Display Date And Time For Each Command


Hello Friend,

I want to set the history command detailed display as per timing, date etc.

I have applied:
#HISTTIMEFORMAT="%d/%m/%y %T "
also
#echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile

but it's set the today's time format only.

Thanks-
Shankar
 
Old 01-27-2012, 01:43 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hello,

What do you mean by 'have applied'? Did you run the command in a shell and expect to apply it always or did you add it to a file to be set automatically upon login?

Kind regards,

Eric
 
Old 01-30-2012, 12:12 AM   #3
JATA01
Member
 
Registered: Nov 2007
Posts: 207

Original Poster
Rep: Reputation: 15
Hi Eric,

Yes I have run this command and also checked in ~/.bash_profile.

Regards-
Shankar
 
Old 01-30-2012, 12:42 AM   #4
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hi,

Can you indicate what distro and version you are using? Don't know if it makes any difference but I have the following in /etc/bash.bashrc and it works flawless for me:
Code:
export HISTTIMEFORMAT="%d/%m/%y %T "
export HISTCONTROL=ignoreboth
export HISTSIZE=2500
Kind regards,

Eric
 
1 members found this post helpful.
Old 01-30-2012, 01:29 AM   #5
JATA01
Member
 
Registered: Nov 2007
Posts: 207

Original Poster
Rep: Reputation: 15
Hi,

It's rhel4.X and rhel5.x

786 30/01/12 09:46:07 cd Linux/
787 30/01/12 09:46:07 ls
788 30/01/12 09:46:07 cd /
789 30/01/12 09:46:07 cd OVO Agent
790 30/01/12 09:46:07 pwd
791 30/01/12 09:46:07 ls
792 30/01/12 09:46:07 cd Linux/
793 30/01/12 09:46:07 ls
794 30/01/12 09:46:07 cd ..
795 30/01/12 09:46:07 cd /
796 30/01/12 09:46:07 cd HP-OVO/
797 30/01/12 09:46:07 LS
798 30/01/12 09:46:07 ls
799 30/01/12 09:46:07 pwd
800 30/01/12 09:46:07 ls
801 30/01/12 09:46:07 cd /
802 30/01/12 09:46:07 ls
803 30/01/12 09:46:07 pwd
804 30/01/12 09:46:07 cd /opt/OV
805 30/01/12 09:46:07 ls
806 30/01/12 09:46:07 cd bin
807 30/01/12 09:46:07 ls
808 30/01/12 09:46:07 cd OpC
809 30/01/12 09:46:07 ls
810 30/01/12 09:46:07 cd install
811 30/01/12 09:46:07 ls
812 30/01/12 09:46:07 cd Agent
813 30/01/12 09:46:07 ls
814 30/01/12 09:46:07 cd Linux
815 30/01/12 09:46:07 ls
816 30/01/12 09:46:07 cd ..
817 30/01/12 09:46:07 cd...
818 30/01/12 09:46:07 pwd
819 30/01/12 09:46:07 cd ..
820 30/01/12 09:46:07 ls
821 30/01/12 09:46:07 cat opcinfo
822 30/01/12 09:46:07 ./ovc -status
823 30/01/12 09:46:07 ls
824 30/01/12 09:46:07 cd ..
825 30/01/12 09:46:07 ls
826 30/01/12 09:46:07 ./opcagt -status
827 30/01/12 09:46:07 cd /HP-OVO/
828 30/01/12 09:46:07 ls
829 30/01/12 09:46:07 pwd
830 30/01/12 09:46:07 ls -ltr
831 30/01/12 09:46:07 chmod -R 777 linux26_x86_860.tar
832 30/01/12 09:46:07 ls
833 30/01/12 09:46:07 ls -ltr
834 30/01/12 09:46:07 tar xvf linux26_x86_860.tar
835 30/01/12 09:46:07 ls -ltr
836 30/01/12 09:46:07 chmod -R 777 RPC_BBC/
837 30/01/12 09:46:07 ls -ltr
838 30/01/12 09:46:07 cd RPC_BBC/
839 30/01/12 09:46:07 ls
840 30/01/12 09:46:07 ./opc_inst -r
841 30/01/12 09:46:07 cd /var/opt
842 30/01/12 09:46:07 ls
843 30/01/12 09:46:07 cd OV
844 30/01/12 09:46:07 ls
845 30/01/12 09:46:07 cd log
846 30/01/12 09:46:07 ls
847 30/01/12 09:46:07 tail -100 opc_inst.log
848 30/01/12 09:46:07 cat opc_inst.log
849 30/01/12 09:46:07 date
850 30/01/12 09:46:07 cd OpC
851 30/01/12 09:46:07 ls
852 30/01/12 09:46:07 tail -100 opcerror
853 30/01/12 09:46:07 ls
854 30/01/12 09:46:07 cd ..
855 30/01/12 09:46:07 ls
856 30/01/12 09:46:07 cd /
857 30/01/12 09:46:07 ls
858 30/01/12 09:46:07 cd HP-OVO
859 30/01/12 09:46:07 ls
860 30/01/12 09:46:07 cd RPC_BBC
861 30/01/12 09:46:07 ls
862 30/01/12 09:46:07 cd /opt/OV/bin
863 30/01/12 09:46:07 ls
864 30/01/12 09:46:07 cd OpC
865 30/01/12 09:46:07 ls
866 30/01/12 09:46:07 cd /
867 30/01/12 09:46:07 ls
868 30/01/12 09:46:07 cd HP-OVO
869 30/01/12 09:46:07 ls
870 30/01/12 09:46:07 cd RPC_BBC
871 30/01/12 09:46:07 ls
872 30/01/12 09:46:07 ./opc_inst -srv 172.28.62.51 -cert_srv 172.28.62.51
873 30/01/12 09:46:07 pwd
874 30/01/12 09:46:07 ls
875 30/01/12 09:46:07 cd /opt/OV
876 30/01/12 09:46:07 ls
877 30/01/12 09:46:07 cd bin
878 30/01/12 09:46:07 ls
879 30/01/12 09:46:07 ./opcagt -status
880 30/01/12 09:46:07 cd OpC
881 30/01/12 09:46:07 ls
882 30/01/12 09:46:07 cd ..
883 30/01/12 09:46:07 ls
884 30/01/12 09:46:07 uname -a
885 30/01/12 09:46:07 df -h
886 30/01/12 09:46:07 df -h
887 30/01/12 09:46:07 cd /oracle/QTY
888 30/01/12 09:46:07 ls
889 30/01/12 09:46:07 cd oraarch/
890 30/01/12 09:46:07 ls
891 30/01/12 09:46:07 ls -ltrh
892 30/01/12 09:46:07 ls -ltrh
893 30/01/12 09:46:07 rm -fr QTYarch1_114* QTYarch1_115* QTYarch1_116*
894 30/01/12 09:46:07 ls -ltrh
895 30/01/12 09:46:07 rm -fr QTYarch1_117* QTYarch1_118* QTYarch1_119*
896 30/01/12 09:46:07 ls -ltrh
897 30/01/12 09:46:07 rm -fr QTYarch1_12*
898 30/01/12 09:46:07 ls -ltrh
899 30/01/12 09:46:07 rm -fr QTYarch1_130* QTYarch1_131* QTYarch1_132* QTYarch1_133* QTYarch1_134* QTYarch1_135*
900 30/01/12 09:46:07 ls -ltrh
901 30/01/12 09:46:07 rm -fr QTYarch1_1360* QTYarch1_1361* QTYarch1_1362* QTYarch1_1363* QTYarch1_1364* QTYarch1_1365*
902 30/01/12 09:46:07 ls -ltrh
903 30/01/12 09:46:07 rm -fr QTYarch1_1366* QTYarch1_1367*
904 30/01/12 09:46:07 ls -ltrh
905 30/01/12 09:46:07 df -h
906 30/01/12 09:46:07 df -h
907 30/01/12 09:46:07 cat /etchosts
908 30/01/12 09:46:07 cat /etc/hosts
909 30/01/12 09:46:07 cat /etc/passwd
910 30/01/12 09:46:07 cd /home/
911 30/01/12 09:46:07 ls -ltr


I run #export HISTCONTROL=ignoreboth
and now it's like:

1006 30/01/12 09:50:05 cat ~/.bash_profile
1007 30/01/12 09:51:24 echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
1008 30/01/12 09:52:11 echo 'export HISTCONTROL=ignoreboth' >> ~/.bash_profile
1009 30/01/12 09:52:16 history
1010 30/01/12 09:52:22 ls
1011 30/01/12 09:52:26 echo 'export HISTCONTROL=ignoreboth' >> ~/.bash_profile
1012 30/01/12 09:52:34 history
1013 30/01/12 09:52:48 ls
1014 30/01/12 09:52:51 history
1015 30/01/12 09:53:09 date
1016 30/01/12 09:53:19 ls
1017 30/01/12 09:53:21 history
1018 30/01/12 09:55:57 ls
1019 30/01/12 09:56:01 history
[root@ascmqty ~]#


Regards,
Shankar
 
Old 01-30-2012, 04:26 AM   #6
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by JATA01 View Post
Hi,

It's rhel4.X and rhel5.x

Code:
786  30/01/12 09:46:07 cd Linux/
  787  30/01/12 09:46:07 ls
  788  30/01/12 09:46:07 cd /
  789  30/01/12 09:46:07 cd OVO Agent
  790  30/01/12 09:46:07 pwd
  791  30/01/12 09:46:07 ls
  792  30/01/12 09:46:07 cd Linux/
  793  30/01/12 09:46:07 ls
  794  30/01/12 09:46:07 cd ..
  795  30/01/12 09:46:07 cd /
  796  30/01/12 09:46:07 cd HP-OVO/
  797  30/01/12 09:46:07 LS
  798  30/01/12 09:46:07 ls
  799  30/01/12 09:46:07 pwd
  800  30/01/12 09:46:07 ls
  801  30/01/12 09:46:07 cd /
  802  30/01/12 09:46:07 ls
  803  30/01/12 09:46:07 pwd
  804  30/01/12 09:46:07 cd /opt/OV
  805  30/01/12 09:46:07 ls
  806  30/01/12 09:46:07 cd bin
  807  30/01/12 09:46:07 ls
  808  30/01/12 09:46:07 cd OpC
  809  30/01/12 09:46:07 ls
  810  30/01/12 09:46:07 cd install
  811  30/01/12 09:46:07 ls
  812  30/01/12 09:46:07 cd Agent
  813  30/01/12 09:46:07 ls
  814  30/01/12 09:46:07 cd Linux
  815  30/01/12 09:46:07 ls
  816  30/01/12 09:46:07 cd ..
  817  30/01/12 09:46:07 cd...
  818  30/01/12 09:46:07 pwd
  819  30/01/12 09:46:07 cd ..
  820  30/01/12 09:46:07 ls
  821  30/01/12 09:46:07 cat opcinfo
  822  30/01/12 09:46:07 ./ovc -status
  823  30/01/12 09:46:07 ls
  824  30/01/12 09:46:07 cd ..
  825  30/01/12 09:46:07 ls
  826  30/01/12 09:46:07 ./opcagt -status
  827  30/01/12 09:46:07 cd /HP-OVO/
  828  30/01/12 09:46:07 ls
  829  30/01/12 09:46:07 pwd
  830  30/01/12 09:46:07 ls -ltr
  831  30/01/12 09:46:07 chmod -R 777 linux26_x86_860.tar
  832  30/01/12 09:46:07 ls
  833  30/01/12 09:46:07 ls -ltr
  834  30/01/12 09:46:07 tar xvf linux26_x86_860.tar
  835  30/01/12 09:46:07 ls -ltr
  836  30/01/12 09:46:07 chmod -R 777 RPC_BBC/
  837  30/01/12 09:46:07 ls -ltr
  838  30/01/12 09:46:07 cd RPC_BBC/
  839  30/01/12 09:46:07 ls
  840  30/01/12 09:46:07 ./opc_inst -r
  841  30/01/12 09:46:07 cd /var/opt
  842  30/01/12 09:46:07 ls
  843  30/01/12 09:46:07 cd OV
  844  30/01/12 09:46:07 ls
  845  30/01/12 09:46:07 cd log
  846  30/01/12 09:46:07 ls
  847  30/01/12 09:46:07 tail -100 opc_inst.log
  848  30/01/12 09:46:07 cat opc_inst.log
  849  30/01/12 09:46:07 date
  850  30/01/12 09:46:07 cd OpC
  851  30/01/12 09:46:07 ls
  852  30/01/12 09:46:07 tail -100 opcerror
  853  30/01/12 09:46:07 ls
  854  30/01/12 09:46:07 cd ..
  855  30/01/12 09:46:07 ls
  856  30/01/12 09:46:07 cd /
  857  30/01/12 09:46:07 ls
  858  30/01/12 09:46:07 cd HP-OVO
  859  30/01/12 09:46:07 ls
  860  30/01/12 09:46:07 cd RPC_BBC
  861  30/01/12 09:46:07 ls
  862  30/01/12 09:46:07 cd /opt/OV/bin
  863  30/01/12 09:46:07 ls
  864  30/01/12 09:46:07 cd OpC
  865  30/01/12 09:46:07 ls
  866  30/01/12 09:46:07 cd /
  867  30/01/12 09:46:07 ls
  868  30/01/12 09:46:07 cd HP-OVO
  869  30/01/12 09:46:07 ls
  870  30/01/12 09:46:07 cd RPC_BBC
  871  30/01/12 09:46:07 ls
  872  30/01/12 09:46:07 ./opc_inst -srv 172.28.62.51 -cert_srv 172.28.62.51
  873  30/01/12 09:46:07 pwd
  874  30/01/12 09:46:07 ls
  875  30/01/12 09:46:07 cd /opt/OV
  876  30/01/12 09:46:07 ls
  877  30/01/12 09:46:07 cd bin
  878  30/01/12 09:46:07 ls
  879  30/01/12 09:46:07 ./opcagt -status
  880  30/01/12 09:46:07 cd OpC
  881  30/01/12 09:46:07 ls
  882  30/01/12 09:46:07 cd ..
  883  30/01/12 09:46:07 ls
  884  30/01/12 09:46:07 uname -a
  885  30/01/12 09:46:07 df -h
  886  30/01/12 09:46:07 df -h
  887  30/01/12 09:46:07 cd /oracle/QTY
  888  30/01/12 09:46:07 ls
  889  30/01/12 09:46:07 cd oraarch/
  890  30/01/12 09:46:07 ls
  891  30/01/12 09:46:07 ls -ltrh
  892  30/01/12 09:46:07 ls -ltrh
  893  30/01/12 09:46:07 rm -fr QTYarch1_114* QTYarch1_115* QTYarch1_116*
  894  30/01/12 09:46:07 ls -ltrh
  895  30/01/12 09:46:07 rm -fr QTYarch1_117* QTYarch1_118* QTYarch1_119*
  896  30/01/12 09:46:07 ls -ltrh
  897  30/01/12 09:46:07 rm -fr QTYarch1_12*
  898  30/01/12 09:46:07 ls -ltrh
  899  30/01/12 09:46:07 rm -fr QTYarch1_130* QTYarch1_131* QTYarch1_132* QTYarch1_133* QTYarch1_134* QTYarch1_135*
  900  30/01/12 09:46:07 ls -ltrh
  901  30/01/12 09:46:07 rm -fr QTYarch1_1360* QTYarch1_1361* QTYarch1_1362* QTYarch1_1363* QTYarch1_1364* QTYarch1_1365*
  902  30/01/12 09:46:07 ls -ltrh
  903  30/01/12 09:46:07 rm -fr QTYarch1_1366* QTYarch1_1367*
  904  30/01/12 09:46:07 ls -ltrh
  905  30/01/12 09:46:07 df -h
  906  30/01/12 09:46:07 df -h
  907  30/01/12 09:46:07 cat /etchosts
  908  30/01/12 09:46:07 cat /etc/hosts
  909  30/01/12 09:46:07 cat /etc/passwd
  910  30/01/12 09:46:07 cd /home/
  911  30/01/12 09:46:07 ls -ltr

I run #export HISTCONTROL=ignoreboth
and now it's like:

Code:
1006  30/01/12 09:50:05 cat ~/.bash_profile
 1007  30/01/12 09:51:24 echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
 1008  30/01/12 09:52:11 echo 'export HISTCONTROL=ignoreboth' >> ~/.bash_profile
 1009  30/01/12 09:52:16 history
 1010  30/01/12 09:52:22 ls
 1011  30/01/12 09:52:26 echo 'export HISTCONTROL=ignoreboth' >> ~/.bash_profile
 1012  30/01/12 09:52:34 history
 1013  30/01/12 09:52:48 ls
 1014  30/01/12 09:52:51 history
 1015  30/01/12 09:53:09 date
 1016  30/01/12 09:53:19 ls
 1017  30/01/12 09:53:21 history
 1018  30/01/12 09:55:57 ls
 1019  30/01/12 09:56:01 history
[root@ascmqty ~]#

Regards,
Shankar
Shankar, always use CODES while pasting output of any commands.

Rest, below commands starts logging date/time when from the time you have used this command on shell. For all previous commands, by default it takes the same date/time only. This makes sense as Linux machine does not logs date/time by default, it logs when you tell it to.

Hope I am clear.
Code:
export HISTTIMEFORMAT="%d/%m/%y %T "
 
Old 01-31-2012, 12:23 AM   #7
JATA01
Member
 
Registered: Nov 2007
Posts: 207

Original Poster
Rep: Reputation: 15
Yes this is the case.

Thanks-
 
Old 01-31-2012, 07:27 AM   #8
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Hi Shankar,

Can you please mark this thread as Solved (follow my signature).
 
Old 07-17-2013, 03:06 AM   #9
barathan
LQ Newbie
 
Registered: Jun 2012
Posts: 17

Rep: Reputation: Disabled
hi All,

so which means we cant get to know the actual time and date of the history? is there any other way to find out the actual date and time of histories?
 
Old 07-17-2013, 04:34 AM   #10
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by barathan View Post
so which means we cant get to know the actual time and date of the history?
It is possible! Have another look at post #4 and post #6.
 
Old 07-17-2013, 04:44 AM   #11
barathan
LQ Newbie
 
Registered: Jun 2012
Posts: 17

Rep: Reputation: Disabled
i did the exact thing on my Linux OpenSUSE machine. when i type history, i got all histories at today date and current time. i wanted to know the actual time. anyway to do this?
 
Old 07-17-2013, 04:51 AM   #12
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by barathan View Post
i did the exact thing on my Linux OpenSUSE machine. when i type history, i got all histories at today date and current time. i wanted to know the actual time. anyway to do this?
Not sure I'm getting what you are saying.


About older, already present entries:
To quote from post #6:
Quote:
commands starts logging date/time when from the time you have used this command on shell. For all previous commands, by default it takes the same date/time only. This makes sense as Linux machine does not logs date/time by default, it logs when you tell it to.
Or are you looking for a different date/time layout? If so: Change the bold part accordingly:
Code:
export HISTTIMEFORMAT="%d/%m/%y %T "
Have a look at the date manual page for the available format options.
 
Old 07-17-2013, 05:30 PM   #13
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
That's "normal" when you first set history timestamp.
Everything in ~/.bash_history will have the timestamp of the date/time you 'set' it.


Check it in an hour after running some terminal commands, you'll see.
 
Old 07-17-2013, 05:57 PM   #14
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
...FWIW though do remember anything unprivileged users can modify themselves should never be mistaken as an authoritative source of information. If an audit trail is important then (in addition to correlation with existing service, user auth logging and BSD accounting) there's logging patches for the shell, shell wrappers like rootsh, tty watchers like snoopy and the audit subsystem.
 
Old 07-19-2013, 06:43 AM   #15
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
The bash_profile files are only read for login shells. For regular interactive shells you need to use your bashrc files.

See the INVOCATION section of the bash man page for details on what startup files it uses in various situations.

Also be aware that changes to a startup file do not immediately apply to the current shell. You have to either log out and back in, re-source the log file, or just run the command again directly.

Last edited by David the H.; 07-19-2013 at 06:45 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unix history with date and time crahuldba@gmail.com Linux - Newbie 1 08-16-2011 07:24 AM
History command with system date shipon_97 Linux - Newbie 5 12-26-2009 02:41 AM
Date comparison with 'string date having slashes and time zone' in Bash only TariqYousaf Programming 2 10-08-2009 07:37 AM
How can I append the date/time stamp to commands in history? abefroman Linux - Security 2 05-29-2008 11:21 AM
History command, How to get the date? philipina Linux - General 2 08-05-2004 05:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration