Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In bash, how does one clear the current input?

Tags:

bash

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?

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?

like image 766
user85509 Avatar asked Jun 29 '09 03:06

user85509


People also ask

How do I abort a bash command?

There are many methods to quit the bash script, i.e., quit while writing a bash script, while execution, or at run time. One of the many known methods to exit a bash script while writing is the simple shortcut key, i.e., “Ctrl+X”. While at run time, you can exit the code using “Ctrl+Z”.


1 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.

like image 327
John Kugelman Avatar answered Sep 23 '22 14:09

John Kugelman