Clear terminal screen using script and a keyboard shortcut

Since I use - - help so often, I want to be able to clear the terminal screen using a Keyboard Shortcut.

This does not clear the terminal that I am using.

#!/bin/bash
# 			
#----------------------------------------------------------------------------
# 
# clears the terminal screen
#----------------------------------------------------------------------------

clear

If I type clear, my terminal clears.

Command is correct, the issue is how you assign the keyboard shortcut.

1 Like

Neither Alt C or Ctrl C works.

I may have to see if I will have to send it to the open terminal?

Just press Ctrl-L. It's a "form feed" character, the character that used to be used by line printers decades ago to force a new page to come out of the printer. Teletype terminals recognized it, too.

3 Likes

I need to clarify things because no one understand what I am asking for help with.

I want to be able to clear the screen at will when I am working in a terminal.

I have my terminal minimized or not.

I want to clear the screen using a keyboard shortcut.

So for example, if I push Alt C, the screen in the terminal clears.

Hi, @DaveHighland :slight_smile:

You wrote:

As far as I can tell, pressing the Ctrl + Shift+R keyboard shortcut / combination, in "MATE Terminal", does NOT clear the terminal screen, but enters the so-called "reverse-i-search" instead (which is a rather useful feature that allows you to search your command history).

To clear the terminal screen, as @fixit7 wants, the key combination that one should press in "MATE Terminal" is Ctrl + L , as @gordon has already mentioned in his earlier response in this topic - "Clear terminal screen using script and a keyboard shortcut - #4 by gordon". Do you agree? :slight_smile:

2 Likes

You guys are not getting it.

I will see if I make it more clearer.

I created a script /home/user/fix7 with contents:

windowid=$(xdotool getwindowfocus)
sleep 0.5
xdotool windowactivate --sync $windowid type 'clear'
xdotool windowactivate --sync $windowid key Return

made it exec chmod +x /home/user/fix7

I went to Control Center, created a custom shortcut
name: clear my screen
command: /home/user/fix7

Then assigned alt+C to that shortcut.

Started a terminal, df, then pressed alt+C .... terminal cleared.

Can someone test this?

3 Likes

It works. You are a good man.

2 Likes

My bad. I defer to your expertise. What probably happened is that long ago I may have double-clicked the line for the "Reset and Clear" shortcut in the Edit/Keyboard Shortcuts... dialog and changed the shortcut to something more memorable (at least for my feeble memory). Sorry for the confusion. I have deleted that reply so as not to lead others astray.

1 Like