Put A TimeStamp on Bash History

Sometimes, it is very helpful to have a timestamp on bash history, that way it’s easier to know the exact time a command was executed.

To put a timestamp on history, run the following command;


That’s all. Next time you run the history command, the history will display with timestamp.

Hope someone finds it useful.

Copying a file to multiple locations

I thought this was cool enough to share.  I have not had to use it however so I doubt it is all that useful 😉

xargs -n 1 cp -v foo.txt<<<"/tmp1/ /tmp2/ /tmp3/"

Here we are copying one file named foo.txt to multiple directories called /tmp/1/, /tmp/2/, and /tmp/3 using xargs.  The xargs command construct argument list(s) and execute utility such as cp.

If you find a use for this let me know.  Backup copies seems useful but other than that…?


Timestamping your bash_history

I use this all the time and occasionally find a server that isn’t configured to timestamp the bash_history. It seemed like something I should preserve here for future reference.

Adding a timestamp is really simple, just execute the following:

echo ‘export HISTTIMEFORMAT=”%d/%m/%y %T “‘ >> ~/.bash_profile ; source ~/.bash_profile

That’s it, now the history command is more useful.

Remember when you issued that command…?

Bash History: Display Date And Time For Each Command

When working in a clustered environment where sometimes documentation gets written past, it is often helpful to know when you issued certain commands. The bash history is great except it doesn’t include a date/time stamp by default. Here is how to add one:

To display the time and date of with previously executed commands in your history, you need to set the “HISTTIMEFORMAT” variable. The variable has to be set in the users profile file so to take effect on each session. You define the environment variable in your bash profile as follows:

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

%d – Day
%m – Month
%y – Year
%T – Time
To see history type

$ history

Sample outputs:

  932  10/12/13 10:48:16 lsof -i
  933  10/12/13 10:49:55 tcpdump -i eth0 src host 137.99.xx.xx
  934  10/12/13 10:50:53 tcpdump -i eth0 src host 137.99.xx.xx port 8080
  935  10/12/13 10:51:10 tcpdump -i eth0 src host 137.99.xx.xx 
  936  10/12/13 10:52:42 ss -ln


For more info type the following commands:

man bash
help history
man 3 strftime

That is it…