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.

  • Are you in a TTY or a GUI terminal emulator. And how exactly did you find that command in your history? – Byte Commander Sep 12 '16 at 16:55
  • in terminal I simply keep pressing up arrow to find the old command – elmclose Sep 12 '16 at 16:59
  • 2
    Look here: askubuntu.com/questions/302263/… – BlueManCZ Sep 12 '16 at 16:59
  • that solution assumes I have xsel -- I have xclip; It assumes I have used Ctrl+P to look for older command -- I simply use up-arrow; and it requires the command xsel to paste -- I prefer to use the normal Shift+Ctrl+V in terminal and Ctrl+V outside it. In fact sometimes I want to paste that text outside the terminal – elmclose Sep 12 '16 at 17:29
  • I typically save history periodically, so I have very old commands once history gets full and lost. 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

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.


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


You will definitely see a list of commands you entered with serial number in the left side against each command say as follows. history example
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


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
    That 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. – elmclose Sep 12 '16 at 18:42

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.