4

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
11

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.

| improve this answer | |
5

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).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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