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
A nice shortcut is pressing Esc#. It will prepend a #
character (thus making the line a comment) and then press enter. If you then decide that you still the need the command, you still have it in your history :)
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
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.)
Alternatively, press Ctrl-C to abort what you're typing.
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.
If you are using Bash in vi mode (set it with set -o vi
), then press Esc to switch to the normal mode of vi, and type dd
to delete the current line!