Linux Command History with Date and Time

Linux Command History with date and time

Regarding this link you can make the first solution provided by krzyk permanent by executing:

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

How to History of commands with dates in linux?

Not easily.

You can see who logged in from where with who or last.

You can see the history of the commands of the last shell which exited in their home folder in the file $HOME/.bash_history. BASH doesn't log the timestamp in this file, though, so there is no way to tell when the commands were executed. You can see this when you execute

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

A lot of the commands in the history will have the same date/time and if you look more closely, you'll see that this is in fact the date/time of the file .bash_history.

It should be possible to download the sources for BASH and compile your own version which does more extensive logging. Just be careful that you don't log commands read from script files (or your computer probably won't even boot anymore).

Also note that you need to do the same for all the shells which your users are using. And you need to make sure that they don't have their own copy of the shell.

Related:

  • How to log all Bash commands by all users on a server?
  • HOWTO BASH Audit / Command Logger

How to show history with timestamp

run the below command in terminal :

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

Or, to make the change permanent for the current user:

echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
source ~/.bashrc
history

How to find date wise history of commands being fired

The history of executed commands is stored by your shell. Try adding something like this to you ~/.bashrc

export HISTTIMEFORMAT="%m/%d - %H:%M:%S: "

It will change the HISTTIMEFORMAT variable and bash will store a timestamp in its history accordingly. Then your history will look like this

487  08/16 - 16:12:01: cd Downloads
488 08/16 - 16:12:04: ls -a
489 08/16 - 16:12:37: cat README | less
490 08/16 - 16:12:58: pkg-config --list-all | grep webkit
491 08/16 - 16:13:04: history

Available identifiers are

%d - Day
%m - Month
%y - Year
%T - Time
%H - Hours
%M - Minutes
%S - Seconds

command history with correct time stamps in unix

If BASHTIMEFORMAT isn't set in a session, the timing information is not saved to the history file (otherwise it is saved as a comment in there).

So unless the user you're trying to log has that in his/her environment, you will not get timing information. It is simply not recorded, so impossible to retrieve.

Real-time display of `date` changes on Linux

I don't know how much the BusyBox shell supports, but in sh you could do something like this:

{ while true ; do date ; sleep 0.1 ; done } | uniq


Related Topics



Leave a reply



Submit