I have two commands I execute frequently. Let's say the first is 'abcd' and the second is 'abc'. So my history contains
1000 abc arg1 arg2 arg3
1001 abcd arg1 arg2 arg3
Now if I type !abcd in bash, it executes the abcd command. which is fine. But if I type !abc in bash, it also executes the last abcd command (since it matches the beginning and is "newer")
How do I use bash history to grab the last abc command? I've tried !'abc ' and "!abc\ " backslashing the space.
You might try reverse history searching: Ctrl-R. On the prompt that appears, type in parts of your commandline (incremental text search).
If you want to switch to the previous match, type some more Ctrl-R.
In your "two similar lines" case,
Ctrl-R abc Ctrl-R
or
Ctrl-R abc<SPACE>
might do it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With