Having found an old (long) command from history I want to copy, modify and execute it. Is there a shortcut key to copy that long string? I do not use mouse.
2 Answers
Press Ctrl + R and start typing a text from a command that you want to get from the history. The latest command with the text that you typed in will appear. Press Ctrl + R again to move to the next command, which contains entered text, until you get the command you are searching for. Then you can move within command with right and left keys and change it as you like. When you are done, just press Enter. You don't need to copy the command as you can recall it anytime.

- 4,362
Well yes there is. Just enter an exclamation mark (!) followed by the command serial number which you can get it from history. For detailed example Open up a terminal and type command
history
You will definitely see a list of commands you entered with serial number in the left side against each command say as follows.
well if you want to execute sudo apt-cache search Inkscape the slno concerned with that command in the above pic is 311 so in the terminal just enter
!311
Well if you want to edit the before executing the command while using above method , you need to set histverify ON so that it will alsways ask for verification before executing. So for that just execute the command once for hassle free use of above method as follows :
shopt -s histverify
Thats it ,

- 1,385
-
1That is certainly a very quick way to execute commands from history, but elmclose wants to edit it before executing. – nobody Sep 12 '16 at 17:36
-
Ok . For that set histverify to ON , this will ask for it. I wll update my answer. Thanks for notifying. – SAGAR Nair Sep 12 '16 at 18:07
-
These are all excellent tips that I didn't know about. However I sometimes need to paste the string outside the terminal such as gedit. – Sep 12 '16 at 18:42
history > hist_Aug2016
That is just a text file which I can copy from, search or use anyway I want. – oldfred Sep 12 '16 at 17:46