Linux – Empty bash command line

bashcommand linelinux

I am looking for a way to delete the currently entered command line without wasting seconds on the Backspace key.

For example I scrolled the bash history and have a long command line that would execute when I pressed Enter:

~$ aptitude search openssl | grep dev

But now I decide that I do not want to execute this command. Can I get an empty prompt fast without deleting the whole line with Backspace? On the Windows cmd you can just press Escape and it is gone. This behavior would be what I want.

Best Answer

Pressing Ctrl+U will empty the current line.

It's the default kill character on most terminals and it erases the current line (from the cursor to its beginning). The stty command can be used to get or set its value.

[dave@hal9000 ~]$ stty -a
speed 38400 baud; rows 23; columns 75; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?;
eol2 = M-^?; swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
...
[dave@hal9000 ~]$ stty kill ^T # Set it to Ctrl-T

Be the way, werase stands for word erase, so Ctrl+W erases the word on the left of the cursor.

Related Question