Bash History: Display Date And Time For Each Command
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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:
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.
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?
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.
...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.
Last edited by David the H.; 07-19-2013 at 06:45 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.