history -d does not remove history entry, but shows time of history entry
Solution 1:
The history
man page you are referring to applies to the Bash shell, but you seem to be using Zsh, that's why the behavior differs.
history
is a shell builtin
Why is the shell you run relevant? Because history
is a shell builtin command, that is, it is not an external executable file installed on your Mac, but a command integrated in the shell.
Zsh and history
If you check man zsh
you will find that history
is an alias for fc -l
:
history
Same as fc -l
and:
fc
The fc command controls the interactive history mechanism.
When the -l flag is given, the resulting events are listed on standard output.
and -d
is one of the options available to fc
:
-d prints timestamps for each event
which is exactly the behavior you get.
Equivalent of history -d
in Zsh
Unfortunately, fc
doesn't include an option to delete lines in the history file, but there are workarounds, for example, check this answer https://stackoverflow.com/a/63494771.
Bash as default shell
If you'd like to use Bash instead of Zsh in Terminal:
- Launch Terminal
- Open the Preferences window by pressing Command,
- Select Shells open with Command and type
/bin/bash
:
IMPORTANT: The Bash version included with macOS is quite old (as of macOS Catalina, the default shell in macOS is Zsh and Bash is deprecated), so if you plan on using Bash regularly, I'd recommend that you install Brew and then Bash.