Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I clear/delete the current line in terminal?

Tags:

bash

terminal

If I'm using terminal and typing in a line of text for a command, is there a hotkey or any way to clear/delete that line?

For example, if my current line/command is something really long like:

> git log --graph --all --blah..uh oh i want to cancel and clear this line <cursor is here now> 

Is there a hotkey or command to go from the above to:

> 

?

Usually I will press the key, and if my current line is a brand new one on the history, that will clear it. But if I'm going through my command history via the key and start editing or using those commands, will only change the prompt to the next newest command in history, so it doesn't work here unless I press multiple times.

like image 823
triad Avatar asked Mar 13 '12 07:03

triad


People also ask

How do you clear the current line in Mac terminal?

Command + K This will clear the entire Terminal screen you're working on, deleting everything. The same thing can be accomplished using Control and L or by typing “clear” into Terminal.

How do you delete a line in Linux?

First, bring your cursor to the line you want to delete. Press the “Esc” key to change the mode. Now type, “:d”, and press “Enter” to delete the line or quickly press “dd”.


1 Answers

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

like image 176
kev Avatar answered Sep 19 '22 03:09

kev