7

When I run history command (on tcsh), it only prints the TIME portion of the timestamp and omits the date:

 3  15:07   echo $PATH
 4  15:07   ls -la

In bash, you can use HISTTIMEFORMAT environmental variable to affect the timestamp forman printed by history command.

E.g. set HISTTIMEFORMAT="[%F %T %Z] "

Is there a way to do this in tcsh and if so, which version of tcsh is required? We have tcsh 6.17.00.

Environment: Red Har Linux 4.4, but I assume the answer shouldn't be affected since history is a shell built-in and not OS-supplied binary.

9

From the tcsh man page.

excerpt

history The first word indicates the number of history events to save. The optional second word (+) indicates the format in which history is printed; if not given, %h\t%T\t%R\n is used. The format sequences are described below under prompt; note the variable meaning of %R. Set to 100 by default.

Example

$ set history= ( 1000 "%h %W/%D/%Y %T %R\n" )

Results in:

$ history
     2 09/08/2014 22:48 set history= ( 1000 "%h %W/%D/%Y %T %R\n" )
     7 09/08/2014 22:49 ls
     9 09/08/2014 22:49 echo "hi"
    10 09/08/2014 22:49 history

This would result in the history being maintained for the last 1000 commands with the format of "%h %W/%D/%Y %T %R\n".

  • %h - history #
  • %W/%D/%Y - month/day/year
  • `%T - 24 hr. time
  • %R - command run

The full descriptions of these macros is defined in the tcsh man page, scroll down to the section where the prompt command is explained. They're there.

  • You have the month & day reversed; you really meant "%W/%D/%Y" for this format: 12/25/2014. :-) – Kevin_Kinsey Nov 9 '15 at 15:02
  • And thank you for the answer ... I was really wondering exactly when I had last run some command or other :-) Seriously. :-) – Kevin_Kinsey Nov 9 '15 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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