tags:

views:

511

answers:

7

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?

A: 

Have you tried the down arrow key?

stanigator
Yes, it doesn't make the input go away.
+3  A: 

Press Ctrl-C to abort what you're typing.

John Kugelman
Thanks, this seems to do the trick.
+1  A: 

Try Control-U. That clears the input line.

gbarry
Thanks, I nearly accepted this as the answer. But I found it clears only the input before the cursor. In some cases I am in the middle of editing the command, so I would rather remember Ctrl+C instead of Ctrl+U as simply "discard the current input".
+1  A: 

Found a short reference at http://www.ice2o.com/bash_quick_ref.html while searching.

ctrl-e (if not at the end of the line) plus ctrl-u will do it.

Roger Pate
A: 

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.

-- can anyone ps try this. http://stackoverflow.com/questions/1056440/undelete-the-deleted-command-in-bash

vks
"Consider that using C-u (or C-e and then C-u) will store what you clear in a buffer so that you can then paste it later using C-y."Markisismea simpler single command is ctrl+_. http://stackoverflow.com/questions/1056440/undelete-the-deleted-command-in-bash answered by john kug-- just started stackoverflow dont have enough points to add comment to you answer.
vks
A: 

Consider that using C-u (or C-e and then C-u) will store what you clear in a buffer so that you can then paste it later using C-y.

A: 

To delete the current line, try:

ctrl-x ctrl-u

As an alternative you may use:

esc-d

which requires in ~/.inputrc:

"\ed": kill-whole-line

see: http://codesnippets.joyent.com/posts/show/1690