Removing history or line numbers from ZSH history file

Solution 1:

Try:

unsetopt EXTENDED_HISTORY

The numbers are the number of seconds since the Unix epoch of when the command began and the duration in seconds that the command ran.

Edit:

I forgot to mention that you should use the fc command to interact with history instead of parsing the history file. There are at least a couple of reasons for this. One is that the history file doesn't have the in-memory entries until you exit the shell, a threshold is met or you explicitly write it with the fc -AI command (I believe). Secondly, you can leave EXTENDED_HISTORY turned on and still interact with the entries without having to remove that information. If it's off, then when you do fc -ld, the shell uses the time that the shell started for the timestamp for commands in the history before that time. If it's off, it remembers the actual date and time (the numbers you're seeing in the file).

See man zshbuiltins.

List the most recent entries:

fc -l

List them without command numbers:

fc -ln

List the most recent 20 commands without command numbers:

fc -ln -20

Include a timestamp and print only the most recent command:

fc -lnd -1

Show all the commands (within the last 50) that include the string "setop" (shows setopt and unsetopt):

fc -l -m '*setopt*' -50