To clear terminal screen in Linux Ubuntu, the simplest command is “clear” to clear terminal screen. To use the clear
command, simply type clear
and press Enter in your terminal window. This will instantly clear the screen.
clear
The clear command doesn’t need any option with itself. Note that in other terminal emulators or UNIX putty, the clear command may just clear the screen for one page and when you scroll, you can still see the old screen and its outputs.
The clear
command in Linux is used to clear the screen of the terminal or console. It helps to remove all the previous output and provide a clean workspace for new commands or information. This can be especially helpful when the terminal window becomes cluttered with too much text.
The command removes all content, including the scrollback buffer (the previous command history). If you want to preserve the scrollback buffer, use the clear command with the -x flag: “# clear -x”
To prevent clearing the scrollback buffer, one can use the clear command with -x option:
clear -x
NOTE: In a Linux terminal, the Ctrl + L
keyboard shortcut is used to clear the terminal screen. It’s equivalent to typing the clear
command in the terminal.
You can also use the reset command to clear the terminal screen. The reset command reinitializes the terminal. The reset command is useful when the terminal doesn’t terminate easily.
The keyboard shortcut to clear the screen terminal is Ctrl+L in Linux. The shortcut works in most terminal emulators. Note that Ctrl+L clears the output and moves the screen one page down. But one can still see the command output history by scrolling up.
Linux Command To Clear Terminal History
To clear the history, type the following command:history -c && history -w
ORrm ~/.bash_history
Clear Bash Shell Terminal History on Logout
You can modify the above command to clear the history when you logout:
echo 'history -c' >> ~/.bash_logout
NOTE: The Terminal history is stored in a file called “.bash_history” located in the home directory.
You can also use reset command. The reset command is helpful when the terminal isn’t working or when it appears “hanged”. Note that in Linux, the reset
command restores Terminal settings as it resets terminal attributes to their default settings. The reset
command clears the terminal screen. To use the command, simply open a terminal and type reset.
Unlike the clear command, the reset command does more as it resets the terminal to its default settings. It restores all settings to its default value.