gpt4 book ai didi

zsh `history n` 显示前 n 个条目而不是最后 n 个条目

转载 作者:行者123 更新时间:2023-12-01 09:08:31 25 4
gpt4 key购买 nike

我阅读了 history 的文档,它说:

  history [n]
history -c
history -d offset
history -anrw [filename]
history -p arg [arg ...]
history -s arg [arg ...]
With no options, display the command history list with line
numbers. Lines listed with a * have been modified. An
argument of n lists only the last n lines.

但在我的 zsh 中,它总是显示前 n 行。我需要使用 history | tail -n 显示最后几行。

  1. 是否有任何选项设置错误?如何纠正?
  2. 此外,如何打印没有行号和时间戳的历史记录,以便我可以将部分历史记录转换为脚本

最佳答案

zshhistory 的文档在 zshbuiltins(1) 中是:

history

Same as fc -l.

其中 fc -l 是:

fc -l [ -LI ] [ -nrdfEiD ] [ -t timefmt ] [ -m match ] [ old=new ... ] [ first [ last ] ]

If first is not specified, it will be set to -1 (the most recent event), or to -16 if the -l flag is given. If last is not specified, it will be set to first, or to -1 if the -l flag is given. However, if the current event has added entries to the history with print -s or fc -R, then the default last for -l includes all new history entries since the current event began.

When the -l flag is given, the resulting events are listed on standard output.

所以运行:

history -<n>

使用连字符减号,如 history -16,查看 zsh 中最后 n 行历史记录。

关于zsh `history n` 显示前 n 个条目而不是最后 n 个条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51316847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com