如何浏览某些行号之间的 bash 历史记录

dur*_*uru 8 linux bash history command-line

每次我需要这个时,我都会用谷歌搜索 10 分钟。我不知道如何更好地表达这一点,以便 Google 立即找到它,但我需要在某些行之间检索 bash 历史记录,例如:

$ history --start 321 --end 456
#to retrieve history from 321 and to 456
Run Code Online (Sandbox Code Playgroud)

小智 15

你可以使用类似的东西

历史 | grep -A 135 -w 321

它从第 321 行开始并显示接下来的 135 行,因此它将显示第 321 到 456 行。


Zin*_*ina 6

使用头部和尾部。

history | head -n 456 | tail -n 136

这将获得前 456 个(直到您想要的最后),然后获得最后一个 136 个(计算为 456 - 136 = 320,但将从历史记录中的第 321 条记录中获取)。