Shortcut to clear command line terminal [duplicate]

Ctrl+U will only clean from the cursor to the beginning of the line, so if the cursor is at the end of the line, all the line will be cleaned, and if not, there will remain the characters after the cursor.

For a complete answer, I will say:

  • Ctrl+U - clear all the current line from the end to the beginning only if the cursor is at the end of the line.

    • You can then recall the cleared line with Ctrl+Y if you need.
  • Ctrl+K - clear all the current line from the beginning to the end only if the cursor is at the beginning of the line.

    • You can then recall the cleared line with Ctrl+Y if you need.
  • Ctrl+W - clear the previous word in the current line. For example if you have typed a command like git diff /path/to/some/file and you want to delete just the last parameter to the command, Ctrl+W is very useful.

    • You can then recall the cleared data using Ctrl+Y if you need.
  • Ctrl+E Ctrl+U - move the cursor to the end of the line and clear all the current line from the end to the beginning.

    • You can then recall the cleared line with Ctrl+Y if you need.
  • Ctrl+A Ctrl+K - move the cursor at the beginning of the line and clear all the current line from the beginning to the end.

    • You can then recall the cleared line with Ctrl+Y if you need.
  • Ctrl+C - my favourite - cancel the current command line, which implies clear all the current line no matter where the cursor is.

    • Disadvantage: you can't recall the cleared line anymore.
  • Alt+Shift+# - comment the current line, keep it in the history and bring up your prompt on a new line.


A shortcut, Ctrl+u should do what you want.