In bash, how does one clear the current input?

前端 未结 11 1950
礼貌的吻别
礼貌的吻别 2020-12-04 05:56

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

相关标签:
11条回答
  • 2020-12-04 06:15

    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 :)

    0 讨论(0)
  • 2020-12-04 06:17

    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

    0 讨论(0)
  • 2020-12-04 06:19
    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.

    0 讨论(0)
  • 2020-12-04 06:20

    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.

    0 讨论(0)
  • 2020-12-04 06:24

    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!

    0 讨论(0)
提交回复
热议问题