0

Is there a way to display a timestamp before every command line in UNIX or Mac OS X?

This is what shows up:

[projects]$ make

This is roughly what I want:

(1/13/2012 12:46.34) [projects]$ make

EDIT: This is what I get from 'echo $PS1':

[\u@\h \W]\$

I want this same functionality but with a timestamp. I am not too familiar with the PS1 variable and its syntax but when I try and put in what echo spits out + a date, it messes all up

4 Answers 4

3

It depends on your shell. If you are using bash:

export PS1='\D{%D %H:%M.%S} [\W]\$ '
0
1

Use the date command.

date - print or set the system date and time

http://linux.about.com/od/commands/l/blcmdl1_date.htm

1
  • ..and add this "date" program output into shell $PS1 variable. :) Sep 27, 2012 at 22:10
1

Set your PS1 variable with date command.

export PS1=$(date):$PWD $

PS1 is usually set in your .basrc file or .profile which you can find in your home directory.

0

In bash, you can type

PS1="($(date +'%Y-%m-%d %H:%M:%S')) [\W]\$ "

then press enter. If you like how it looks, put that line at the end of your ~/.bashrc file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.