ale ale - 2 months ago 18
Linux Question

Using bash history to get a previous command, copy it and then 'run' it but with the command commented

Just a question to improve my

skills. I always do this:

$ history | grep some_long_command

123 some_long_command1.........
124 some_long_command2.........

I can then run the command the command I found by doing:


However, I often want to do this:


I.e. change the command before I run it. Can you use bash to run this command instead:


so it gets commented.

Then I don't have to use my mouse to highlight the command, edit it and then run it (I can just use the keyboard - faster).

I suppose I could write a script to do it but there might already be functionality built in somewhere....?

Thank you.


I'd suggest instead of using the history command, you use ctrl+r and start typing that command. When you press an arrow key as if to go to modify it, it will drop out of autocomplete recognition, and will let you edit before running.

UPDATE: also, if you want to cycle through the different commands that contain the string you just typed, keep on pressing ctrl+r