In bash, how does one clear the current input?

Viewed 45587

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?

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

11 Answers
  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.

Try Ctrl+U. That clears the input line.

There are two options to do this

ctrl+c - this clears the whole line, no matter where the cursor is.

ctrl+u - this clear the line from the position of the cursor until the beginning.

Consider that using Ctrl-U (or Ctrl-E and then Ctrl-U) will store what you clear in a buffer so that you can then paste it later using Ctrl-Y.

Related