Macos – the difference between Ctrl+L and Cmd+K for clearing the terminal screen

keyboard shortcutsmacosterminal

I've to realize that both of these keyboard shortcuts accomplish the exact same goal: clearing the terminal screen in OS X.

The only discernible difference I can see is that the Cmd ⌘+K shortcut actually see enters the Edit tab in the menu bar, but Ctrl+L does not, clearly indicating that different things are happening.

What is happening differently in the use of these different shortcuts? Why are there two shortcuts that clear the screen, and is this "2 shortcut – 1 result" a general theme in OS X?

Best Answer

One difference is that Cmd+K clears the scrollback buffer as well as the screen. Ctrl+L only clears the screen, effectively moving what is on it "up" into the scrollback buffer.

Another difference is that Ctrl+L is performed by the process running inside Terminal. For instance, bash will clear the screen and redraw the prompt, including any unfinished command there. Other programs might not do anything, or might refresh the screen without clearing it.

Cmd+K, on the other hand, is performed by Terminal itself, regardless of what's running in the window, so it might hide the output from the program.

There are two short-cuts (or more) because you are interacting with two programs, Terminal and whatever process is running inside of it. I wouldn't say this is typical of OS X. Rather, it's a common occurence in any multi-layered computing environment. You'd have to run (only) DOS (without any TSR) to experience an environment where all keyboard short-cuts were interpretted by a single application. But since the two short-cuts in this case do different things, the overlap is really only superficial. For instance, Cmd+w and Cmd+q might appear to do the same thing to some users, but in fact, they are different. The same is true for Ctrl+L and Cmd+K.