zsh history is too short

前端 未结 2 1767
你的背包
你的背包 2020-12-05 04:31

When I run history in Bash, I get a load of results (1000+). However, when I run history the zsh shell I only get 15 results. This makes grepping h

2条回答
  •  自闭症患者
    2020-12-05 04:42

    NVaughan (the OP) has already stated the answer in an update to the question: history behaves differently in bash than it does in zsh:

    In short:

    • zsh:
      • history lists only the 15 most recent history entries
      • history 1 lists all - see below.
    • bash:
      • history lists all history entries.

    Sadly, passing a numerical operand to history behaves differently, too:

    • zsh:
      • history shows all entries starting with - therefore, history 1 shows all entries.
      • (history - - note the - - shows the most recent entries, so the default behavior is effectively history -15)
    • bash:
      • history shows the most recent entries.
      • (bash's history doesn't support listing from an entry number; you can use fc -l , but a specific entry must exist, otherwise the command fails - see below.)

    Optional background info:

    • In zsh, history is effectively (not actually) an alias for fc -l: see man zshbuiltins
      • For the many history-related features, see man zshall
    • In bash, history is its own command whose syntax differs from fc -l
      • See: man bash
    • Both bash and zsh support fc -l [] to list a given range of history entries:
      • bash: specific entry must exist.
      • zsh: command succeeds as long as least 1 entry falls in the (explicit or implied) range.
      • Thus, fc -l 1 works in zsh to return all history entries, whereas in bash it generally won't, given that entry #1 typically no longer exists (but, as stated, you can use history without arguments to list all entries in bash).

提交回复
热议问题