Sei sulla pagina 1di 2

sign up

Unix & Linux Stack Exchange is a


question and answer site for users of
Linux, FreeBSD and other Un*x-like
operating systems. Join them; it only
takes a minute:

datetime stamp when running history command in zsh shell


When I run the history command on my ubuntu server, I get output as follows:
history
...
25 cd ~
26 ls -a
27 vim /etc/gitconfig
28 vim ~/.gitconfig

I want to view the datetime of a particular user. However when I assume them:
su otheruser
export HISTTIMEFORMAT='%F %T
history
...
25 cd ~
26 ls -a
27 vim /etc/gitconfig
28 vim ~/.gitconfig

'

It still doesn't show datetime. I am using zsh shell.


/ command-history

edited Dec 2 '13 at 19:06

asked Dec 2 '13 at 18:58

JohnMerlino
726

14

28

1 Answer

I believe the HISTTIMEFORMAT is for Bash shells. If you're using zsh then you could use these
switches to the history command:

Examples
$ history -E
1
2.12.2013 14:19

history -E

$ history -i
1 2013-12-02 14:19

history -E

$ history -D
1 0:00 history -E
2 0:00 history -i

If you do a man zshoptions or man zshbuiltins you can find out more information about these
switches as well as other info related to history .
excerpt from zshbuiltins man page
Also when listing,
-d
prints timestamps for each command
-f
prints full time-date stamps in the US `MM/DD/YY hh:mm' format
-E
prints full time-date stamps in the European `dd.mm.yyyy hh:mm' format
-i
prints full time-date stamps in ISO8601 `yyyy-mm-dd hh:mm' format
-t fmt prints time and date stamps in the given format; fmt is formatted
with the strftime function with the zsh extensions described for
the %D{string} prompt format in the section EXPANSION OF PROMPT
SEQUENCES in zshmisc(1). The resulting formatted string must be no
more than 256 characters or will not be printed.
-D
prints elapsed times; may be combined with one of the options above.

Debugging invocation
You can use the following 2 methods to debug zsh when you invoke it.
Method #1
$ zsh -xv

tour

help

Here's how it works:

Anybody can ask


a question

Sign up

log in

Anybody can
answer

The best answers are voted


up and rise to the top

Method #2
$ zsh
$ setopt XTRACE VERBOSE

In either case you should see something like this when it starts up:
$
#
#
#
#
#
#
#
#

zsh -xv
/etc/zshenv is sourced on all invocations of the
shell, unless the -f option is set. It should
contain commands to set the command search path,
plus other important environment variables.
.zshenv should not contain commands that produce
output or assume the shell is attached to a tty.

#
# /etc/zshrc is sourced in interactive shells. It
# should contain commands to set up aliases, functions,
# options, key bindings, etc.
#
## shell functions
...
...
unset -f pathmunge _src_etc_profile_d
+/etc/zshrc:49> unset -f pathmunge _src_etc_profile_d
# Created by newuser for 4.3.10
edited Dec 3 '13 at 0:24

answered Dec 2 '13 at 19:24

slm
170k

43

317

"event not found: -i " "event not found: -E". Do I need to load something in a config file before running these
switches? JohnMerlino Dec 2 '13 at 19:41
Are you sure you're in a zsh ? I'm using a vanilla zsh that I run and it has them. slm Dec 2 '13 at 19:43

What version of zsh ? zsh --version . I just confirmed on Ubuntu 12.10 that the commands I gave you worked
just fine. slm Dec 2 '13 at 19:52

11

@JohnMerlino I had zsh 4.3.10 (x86_64-unknown-linux-gnu) on a server for which I wanted to view history with
timestamps. After looking through the zshbuiltins man page, I discovered that I needed to use fc . What
finally worked for me was fc -li . You can pass command numbers to fc , too, so fc -li -100 lists the last
100 commands in your history. Thomas Upton Jul 23 '14 at 13:11

10

I have to use \history -E , I use oh-my-zsh juanpastas Sep 25 '14 at 22:30

487

Potrebbero piacerti anche