LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to view the history with the actual timestamp for the commands? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-view-the-history-with-the-actual-timestamp-for-the-commands-4175460005/)

sujithspillai90 04-29-2013 09:30 AM

How to view the history with the actual timestamp for the commands?
 
Hello Friends,

Please could anyone help me to get the actual timestamp using history for the commands typed as user or root.

I have tried using export HISTTIMEFORMAT="%F %T "
and then the history does not give me the actual timestamp, it is showing the current timestamp for all the commands in the history. SO I would like to understnad if it is possible to get the actual timestamp for the history command. It will help me to identify who did/what did/ and when did on my servers.

Aprreciate your help in this.

rosehosting.com 04-29-2013 09:54 AM

You can try with 'export HISTTIMEFORMAT="%d/%m/%y %T "'.

Just add the 'export' command to your '.bash_profile':

Code:

echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
and execute:

Code:

source ~/.bash_profile

sujithspillai90 04-29-2013 10:13 AM

You are great. Thank you very much for the help.

sujithspillai90 05-02-2013 10:18 AM

Dear Friends,

I have tried it in bash and its working superb. But what should I do for C-shells and K-shells. I have tried a bit but nothing worked.please could anyone suggest.

shivaa 05-02-2013 10:56 AM

In C-shell use setenv command instead of export cmd.
Code:

~$ setenv HISTTIMEFORMAT "%d/%m/%y %T "
Or, add it to your .cshrc or .profile file:
Code:

~$ echo 'setenv HISTTIMEFORMAT "%d/%m/%y %T "' >> ~/.cshrc

chrism01 05-02-2013 09:34 PM

ksh:

1. try http://www.howtoguides.com/computers.../history.xhtml as referenced in http://h30499.www3.hp.com/t5/Languag...e/td-p/4763299

2. alternately (if that won't work) go to the latter thread and just after that ref (2 posts down) see another option using trap cmd.

sujithspillai90 05-03-2013 06:39 AM

Thank you.

It didnt helped me...still I am seeing the history output with time only. Is there any other options.


Also for k-shell also nothing helped me as of now. Please any advise.

shivaa 05-03-2013 08:22 AM

Quote:

Originally Posted by sujithspillai90 (Post 4944049)
It didnt helped me...still I am seeing the history output with time only. Is there any other options.

I am sorry if I misunderstood it, but we've just suggested you that how can you set a variable in C and K shells. However, let's know what exactly you want to do?

If your concern is just to check the history of commands for a particular user, then check that user's /home/username/.bash_history file. On the other hand, you can check your systems various logs (i.e. /var/log/... files) to find out who and what a user did on your server.

The command:
Code:

~$ setenv HISTTIMEFORMAT "%d/%m/%y %T "
Will just save a string (i.e. %d/%m/%y %T) in HISTTIMEFORMAT variable, and nothing else. Also using the history command in C shell you will be able to see what command was run at what time.
Code:

~$ history


All times are GMT -5. The time now is 04:32 AM.