Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

You know the situation: You are halfway through typing a long command (for example a commit message) and realize that you have forgotten to execute some prerequisite command that can not be added with &&. Normally when that happens to me, I select what I have typed with the mouse, copy it to the clipboard, press Ctrl-U to clear the line, run my prerequisite command and paste form the clipboard. But maybe there is a better way, preferably without needing to use the mouse? I'm looking for solutions for bash and/or zsh.

share|improve this question
up vote 16 down vote accepted

After you've used CTRL-U you can use CTRL-Y to paste back what you've erased. It works after erasing a word or a number of words with CTRL-W too.

Note this way you don't really need to copy anything to the clipboard or select it with the mouse - CTRL-U actually yanks the line to a separate clipboard, so to speak.

share|improve this answer

Add a '#' to the beginning of your current line. Hit enter to add the comment to your history. Execute the prerequisite command. Go up to the previous command and delete the #.

share|improve this answer

This was recently asked and discussed over on SE's Unix & Linux site. My answer explained that if you use zsh as your shell, you can use the push-line feature to stash your command-in-progress away, run something else, then your first command will come back and you can finish it. In .zshrc:

bindkey '^L' push-line

Then use Ctrl+L to suspend the current command and come back to it after running something else.

Several other answers were given including settings for how to do something similar in bash and some customized versions of this builtin in zsh.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.