bashinput

In Bash, how does one clear the current input?


Suppose in Bash you start writing a command like:

rm -rf /foo/bar/really/long/path/here

and then realize you don't want to execute this after all. Is there a way to clear the input with one or two keystrokes?

I have been prepending echo, enclosing the input in quotes (Ctrl + A, echo ", Ctrl + E, "), and then hitting Enter. Is there a faster way?


Solution

    1. Press Ctrl-U to delete everything before the cursor. The deleted command will be stored into a buffer. Press Ctrl-Y to paste the deleted command.

      (Optional: Press End or Ctrl-E to jump to the end of the input first.)

    2. Alternatively, press Ctrl-C to abort what you're typing.