1

In its documentation, https://ss64.com/osx/history.html it says the -d parameter followed by ID of the history entry will remove an entry from command history. In the picture below you can see that it just shows me 15 entries after the given number with time next to it. Removing -d parameter does the same, but time is not shown.

What's up with this? And how do I remove an entry if the official way does not work?

Edit: I found out when typing type history, that using omz introduced some nonstandard omz_history, which might be causing the problem.

demonstration

1
  • Shouldn’t you start a new shell session in order for change (delete) to take effect? Commented Nov 11, 2021 at 14:09

1 Answer 1

3

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:

  1. Launch Terminal
  2. Open the Preferences window by pressing Command,
  3. Select Shells open with Command and type /bin/bash: enter image description here

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .