Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Maybe I can just remove those first 15 characters easily with regex... uhh.. any thoughts. –  Joseph 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. –  Joseph 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
add comment

1 Answer

up vote 4 down vote accepted

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
share|improve this answer
    
yah I tried this it doesn't seem to affect anything. –  Joseph Silvashy Feb 21 '10 at 1:27
    
Does it show "extendedhistory" among others when you enter the setopt command without any arguments at the shell prompt? –  Dennis Williamson Feb 21 '10 at 1:38
    
Fantastic! Thanks, that solves alot of things, and it also shows incomplete lines that were never sent from ZLE, that's sort of amazing. –  Joseph Silvashy Feb 21 '10 at 1:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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