Starting with macOS Catalina, Apple’s default shell for the Terminal changed from bash to zsh. As part of that change, the behavior of the history command changed.
Bash:
Running the history command lists all history entries.
Zsh:
Running the history command lists only the 15 most recent history entries.
To see more history entries, you can pass a numerical value to the history command. However, the bash and zsh shells handle this differently also.
Bash:
history (number_goes_here): Shows the most recent entries as defined by the number.
For example, the command shown below will show the fifteen most recent entries:
history 15
Zsh:
history (number_goes_here): Shows all entries which follow number_goes_here.
For example, the following command will show all history entries after history entry #1 (which will include all history entries):
history 1
history -(number_goes_here): Shows the most recent entries as defined by the number.
For example, the command shown below will show the fifteen most recent entries:
history -15
For those interested in why this behavior is different, I recommend reading the zshbuiltins manpage’s section on the fc command. This can be accessed by running the following command:
man zshbuiltins
The reason is that in the zsh shell, the history command’s mechanism is using the following built-in function:
fc
For my own needs, I wanted to recreate bash‘s default behavior for the history command in the zsh shell. The way I chose to do this was to add the following line to the .zshrc file in my home folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias history='history 1' |
The .zshrc file is the configuration file for the zsh shell and is used to customize the zsh shell’s behavior. Adding this line to the .zshrc file will run the following command whenever the history command is invoked:
history 1
The downside to this approach is that it interferes with the original functionality of the history command. An alternative approach would be to add the following line to the .zshrc file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias fullhistory='history 1' |
Now all history entries will be displayed when the following command is entered:
fullhistory