我使用该命令history | grep <key_word>查找历史记录中具有该特定key_word 的所有命令。这很好,但有时还不够:我希望看到每个结果之前的 N 个命令和之后的 M 个命令。
例如history | grep build,我想查看每个结果之前的 N=10 个命令和之后的 M=5 个命令。以以下理想输出为目标:
1209 git status
1210 git add .
1211 git commit -m 'bla bla bla'
1212 git push http://xxx.xxx.xx.x:xxxxx/
1213 git tag
1214 source tools/settings.sh
1215 cd demos/xxxxxxx/
1216 xxxxxxx
1217 cd demos/wait_zcu102/
1218 ls
1219 cd build.sw/ <------------------------------------- <key_word> is here
1220 ls
1221 atom .
1222 source tools/settings.sh
1223 cd demos/xxxxxxxxx/
1224 xxxxx
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?