6

For some reason I get these odd line numbers or history numbers of some sort into my ~/.zsh_history file like so:

: 1266694881:0;rake db:migrate

I'd rather not have to resort to regexing out the beginning, but I'd like my lines to be something like:

rake db:migrate

Does anyone have any suggestions for how to solve this? I've found setopt EXTENDED_HISTORY but it doesn't seem to do much.

JP Silvashy
  • 1,387
  • 6
  • 22
  • 30
  • Maybe I can just remove those first 15 characters easily with regex... uhh.. any thoughts. – JP Silvashy Feb 20 '10 at 22:48
  • I don't understand everything : do you have these numbers on every lines ? Do you know what these numbers are or do you only want to remove them ? – Studer Feb 20 '10 at 23:08
  • I actually don't know what they are for, if you are using ZSH, check it out in `~/.zsh_history` I'd rather ZSH not save that portion with the history at all, my interim solution for searching history is as such `cat ~/.zsh_history | grep $1 | sed "s/...............//"` But this is ridiculous. – JP Silvashy Feb 20 '10 at 23:11
  • 1
    `grep $1 ~/.zsh_history | cut -c 16-` – Dennis Williamson Feb 20 '10 at 23:14
  • I don't have any of these numbers in my zsh history. What version of zsh are you running ? what is the content of your .zshrc ? – Studer Feb 20 '10 at 23:37

1 Answers1

13

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
Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148