For example, I have formed a long complicated command that will improve the world and lower an entropy in the Universe. But then (huh!) I see that I forgot to make a dir required. I want to store my command, run mkdir and then restore my command.

Assume doing it in a raw tty.

Is there a way to do so?

  • I'm assuming you can't copy and paste? Just put a # at the beginning of the line and then run it. It'll be stored in the bash history where you can retrieve it, delete the # and the run it properly.
    – qasdfdsaq
    Jul 24, 2015 at 10:26

2 Answers 2


On your command-line press Ctrl-u (it stores it in the kill-ring), issue the other one mkdir for example, and then press Ctrl-y.


Use set -o vi command or set -o emacs (typically one would store this in .bashrc for convenience). This enables a vi-style (or emacs type) line editing interface.

This provides you with a command line vi editor. You can search for previous commands, edit commands, etc.


Use ESC key to enter vi command mode, then

$ /search-string

Use UP and DOWN keys, (or j and k) to list found commands

$ long-command-you-want-to-edit

Hit ESC key type vi Then edit the long command in a vi editor.

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.