Some things about shell (zsh) history I don’t want to forget.

Showing history

Use a negative argument to specify how far back to list. For example, to list the last 25 commands:

% history -25

The -i option shows timestamps (required EXTENDED_HISTORY to be enabled to save timestamps):

% history -i

To update a shell’s history from sessions in other windows:

% fc -RI

History aliases:

alias h=' fc -li' # history w/timestamp
alias rh=' fc -RI' # refresh history


Use option-. to insert last word from prior command:

% mkdir newdir
% cd # press option-. to insert "newdir" from prior command

I don’t use it as often with the corrections enabled in zsh, but the ability to replace strings in the previous command is still useful at times. With CORRECT and CORRECT_ALL not enabled:

% mkdir newdir
% cd newdr
cd: no such file or directory: testdr
% ^dr^dir
cd testdir

Tags: ,