Terminal: What is the shortcut to clean your command line

If I have this:

$ bla bla bla bla

Is there any shortcut for Terminal (MacOS) to clean the entire line?


Solution 1:

The command to discard (kill) the whole line is not usually assigned a keyboard shortcut. Ctrl-U will only kill from the beginning of the line to the cursor.

Press both Ctrl-U (prefix) and Ctrl-K (suffix) to remove the whole line, no matter where the cursor is.

Here's a bash reference with the different commands and their default keyboard shortcuts.

You can assign a keyboard shortcut to kill-whole-line by editing ~/.inputrc. Add the following line:

"\C-k": kill-whole-line

This will assign Ctrl-K the "kill whole line" command.

Solution 2:

Following is for Linux bash, but I suppose this should work for Mac also:

Clear input line:

Ctrl + U

Another trick is just:

Ctrl + C