Is this normal behavior for MacOS Big Sur ZSH (Z Shell) terminal? Sometimes shell commands such as find and or launchd as just a simple example execute properly. This is with the exclamation symbol "!" in front, leading with the expected output and no privilege escalation.

For example, running: !find / will still work. Or !sudo will execute.

But !echo '@' will not. But lead to the next command sometimes.

Output for !echo

zsh: event not found: echo

Output for !launchd


launchd cannot be run directly.

It seem's weird !sudo outputs sudo syscallbypid.d

1 Answer 1


!str Refer to the most recent command starting with str. this is the history expansion behavior. type

man zshexpn

and check 'Event Designators', you will get the answer

An event designator is a reference to a command-line entry in the history list. In the list below, remember that the initial `!' in each item may be changed to another character by setting the histchars parameter.

   !      Start a history expansion, except when followed by a blank, newline, `=' or `('.  If followed immediately by a word designator
          (see the section `Word Designators'), this forms a history reference with no event designator (see the section `Overview').

   !!     Refer to the previous command.  By itself, this expansion repeats the previous command.

   !n     Refer to command-line n.

   !-n    Refer to the current command-line minus n.

   !str   Refer to the most recent command starting with str.

          Refer to the most recent command containing str.  The trailing `?' is necessary if this reference is to be followed by a modi-
          fier or followed by any text that is not to be considered part of str.

   !#     Refer  to  the  current command line typed in so far.  The line is treated as if it were complete up to and including the word
          before the one with the `!#' reference.

   !{...} Insulate a history reference from adjacent characters (if necessary).
  • 1
    Possibly of note, while ZSH has a handful of quirks, most of this is in fact not unique to ZSH, and works largely similarly in most other modern shells that provide history expansion. Commented Apr 18, 2021 at 16:25
  • @nelson Thanks for the great answer really informative and appreciated. Also, Austin thanks for that info as well.
    – ABC
    Commented Apr 18, 2021 at 18:04

You must log in to answer this question.

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