How do I clear/delete the current line in terminal?
You can use Ctrl+U to clear up to the beginning.
You can use Ctrl+W to delete just a word.
You can also use Ctrl+C to cancel.
If you want to keep the history, you can use Alt+Shift+# to make it a comment.
Bash Emacs Editing Mode Cheat Sheet
Just to summarise all the answers:
- Clean up the line: You can use Ctrl+U to clear up to the beginning.
- Clean up the line: Ctrl+E Ctrl+U to wipe the current line in the terminal
- Clean up the line: Ctrl+A Ctrl+K to wipe the current line in the terminal
- Cancel the current command/line: Ctrl+C.
- Recall the deleted command: Ctrl+Y (then Alt+Y)
- Go to beginning of the line: Ctrl+A
- Go to end of the line: Ctrl+E
- Remove the forward words for example, if you are middle of the command: Ctrl+K
- Remove characters on the left, until the beginning of the word: Ctrl+W
- To clear your entire command prompt: Ctrl + L
- Toggle between the start of line and current cursor position: Ctrl + XX
I have the complete shortcuts list:
- Ctrl+a Move cursor to start of line
- Ctrl+e Move cursor to end of line
- Ctrl+b Move back one character
- Alt+b Move back one word
- Ctrl+f Move forward one character
- Alt+f Move forward one word
- Ctrl+d Delete current character
- Ctrl+w Cut the last word
- Ctrl+k Cut everything after the cursor
- Alt+d Cut word after the cursor
- Alt+w Cut word before the cursor
- Ctrl+y Paste the last deleted command
- Ctrl+_ Undo
- Ctrl+u Cut everything before the cursor
- Ctrl+xx Toggle between first and current position
- Ctrl+l Clear the terminal
- Ctrl+c Cancel the command
- Ctrl+r Search command in history - type the search term
- Ctrl+j End the search at current history entry
- Ctrl+g Cancel the search and restore original line
- Ctrl+n Next command from the History
- Ctrl+p previous command from the History
Ctrl+A, Ctrl+K to wipe the current line in the terminal. You can then recall it with Ctrl+Y if you need.