1

Everytime I need this I google it like 10 minutes. I don't know how to express this better so that Google finds it right away but I need to retrieve bash history between certain lines like:

$ history --start 321 --end 456
#to retrieve history from 321 and to 456
3

You can use something like

history | grep -A 135 -w 321

It starts with line 321 and shows the next 135 lines, so it will show lines 321 to 456.

1

Use head and tail.

history | head -n 456 | tail -n 136

Which will get the first 456 (up to the end you want) and then you get the last 136 (which computes as 456 - 136 = 320, but will fetch from the 321st record from history).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.