clear

terminal controlLinux/Unix
The clear command is one of the most frequently used commands in Linux/Unix-like operating systems. clear Clear the terminal screen

Quick Reference

Command Name:

clear

Category:

terminal control

Platform:

Linux/Unix

Basic Usage:

clear [options] [arguments]

Common Use Cases

    Syntax

    clear [OPTION]

    Options

    Option Description
    -T TERM Use this terminal type instead of the value of $TERM
    -V Display version information and exit
    -x Do not attempt to clear terminal's scrollback buffer

    Examples

    How to Use These Examples

    The examples below show common ways to use the clear command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    #

    Basic Examples:

    # Clear the entire screen
    clear
    # Clear screen and display program version clear -V
    # Use with other commands to provide clean output clear && ls -la
    # Use ANSI escape sequence (alternative method) echo -e "\033c"

    Advanced Examples:

    # Clear screen before running a script
    clear && ./myscript.sh
    # Add to .bashrc to create a custom clear command echo 'alias cls="clear && echo \"Terminal cleared on $(date)\""' >> ~/.bashrc
    # Clear screen and show system information clear && echo "$(hostname) - $(date)" && uptime # Create a function that clears and shows a header echo 'function clear_with_header() { clear; echo "===== $(hostname) ====="; }' >> ~/.bashrc

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The clear command clears your terminal screen. It uses terminal capabilities in the terminfo database to determine how to clear the screen for the current terminal type.

    Key points about the clear command:

    • It is a simple utility that's available on virtually all Unix-like systems
    • It works by sending the appropriate control sequences to the terminal
    • It respects the current terminal type specified in the TERM environment variable
    • By default, it attempts to clear both the visible screen and the scrollback buffer
    • The command is equivalent to the Control+L keystroke in many terminal emulators

    Alternative methods to clear the screen:

    • Using the keyboard shortcut Ctrl+L in most terminals
    • Using the ANSI escape sequence: echo -e "\033c"
    • Using reset command for a more thorough reset (slower but fixes terminal issues)
    • Using tput clear (more portable across different terminal types)

    The clear command is commonly used in scripts when you want to provide a clean interface for the user, removing previous output before displaying new information.

    Related Commands

    These commands are frequently used alongside clear or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the clear command works in different scenarios.

    $ clear
    View All Commands