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 |
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 |
Hi Eric,
Yes I have run this command and also checked in ~/.bash_profile. Regards- Shankar |
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 " Eric |
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 |
Quote:
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 " |
Yes this is the case.
Thanks- |
Hi Shankar,
Can you please mark this thread as Solved (follow my signature). |
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? |
Quote:
|
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?
|
Quote:
About older, already present entries: To quote from post #6: Quote:
Code:
export HISTTIMEFORMAT="%d/%m/%y %T " |
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. |
...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.
|
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. |
All times are GMT -5. The time now is 11:01 PM. |