FUNDAMENTALS A Complete Guide for Beginners
The clear command in Linux is a very easy-to-use command that is used for clearing the terminal screen. In this article, you will learn the syntax, options, and practical applications of the clear command in Linux.
A. Description
The clear command clears your terminal screen if possible. It also scrolls down the terminal screen to clear it. It observes the terminal type in the environment given by the environment variable TERM, and then in the terminfo database to decide how the screen can be cleared. Standard output is also written by the clear command in Linux.
B. Syntax
The clear command in Linux has a simple syntax. The syntax of the command is as follows:
clear [-OPTION]
Note: In the syntax above, OPTION is enclosed by a square bracket representing that one option can be used in a single command.
C. Options
The clear command has a few options. I have listed them here. However, if you want to gain more knowledge about the options of the clear command you can look for the man page for the clear command.
man clear
Useful Options
- -T, Indicates the type of terminal
- -V, Reports the version of ncurses
- -x, Scrolls down the terminal, does not remove history
Note: The options in Linux CLI (Command Line Interface) are case-sensitive, so be careful while using them.
Practical Examples of the “clear” Command in Linux
The clear command is used to clear the terminal screen. It is a very simple command. Here you will get to know some examples of the clear command in Linux.
Example 1: Clear the Terminal Using the “clear” Command in Linux
To clear the terminal screen, I am using the clear command. To do the same you can follow the procedure below:
Steps to Follow >
➊ At first open the Ubuntu Terminal.
➋ Write some random commands.
➌ To clear the terminal, type the following command in the command prompt:
clear
❹Now, press the ENTER button.
Output >
As you can see, the clear command cleared everything on the terminal screen.
Before executing the “clear” command >After executing the “clear” command >
- The “alias” Command in Linux [3 Practical Examples]
- The “unalias” Command in Linux [3 Practical Examples]
- The “exit” Command in Linux [5 Practical Examples]
Example 2: Scroll Down the Terminal Using the “clear” Command in Linux
To clear the terminal screen without removing history, I am using the clear command with the option -x. It actually scrolls down the terminal screen. To do the same you can follow the procedure below:
Steps to Follow >
➊ At first open the Ubuntu Terminal.
➋ Write some random commands.
➌ To clear the terminal without removing history, type the following command in the command prompt:
clear -x
❹ Now, press the ENTER button.
Output >
In the following images, the output displays the clear command scrolled down the terminal screen.
Before executing the “clear -x” command >After executing the “clear -x” command >
Note: You can also press CTRL + L instead of clear -x. This is one of the shortcuts used in Linux.
Example 3: Reset the Terminal
To re-initialize the terminal, you can also use the reset command in Linux.
Steps to Follow >
➊ At first open the Ubuntu Terminal.
➋ To re-initialize the terminal, type the following command in the command prompt:
reset
➌ Now, press the ENTER button.
Output >
In the images below, the output displays the reset command re–initialized the terminal screen.
Before executing the “reset” command >After executing the “reset” command >
Conclusion
As you have seen in this section, the clear command has less usage in Linux. Here you’ve got to know the syntax, options, and practical application of this command. You have also seen a glimpse of the reset command in Linux. If you want to become an expert in Linux, go through the details of the command and its practical applications.
Related Articles
- The “bash” Command in Linux [5 Practical Examples]
- The “echo” Command in Linux [7 Practical Examples]
- The “declare” Command in Linux [7 Practical Examples]
- The “export” Command in Linux [8 Practical Examples]
- The “source” Command in Linux [3 Practical Examples]
- The “hash” Command in Linux [6 Practical Examples]
- The “read” Command in Linux [8 Practical Examples]
- The “set” Command in Linux [6 Practical Examples]
- The “unset” Command in Linux [2 Practical Examples]
- The “eval” Command in Linux [4 Practical Examples]