Linux command
clear 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Clear the terminal screen
clear
Clear and reset scrollback buffer
clear -x
Clear for a specific terminal type
clear -T [xterm-256color]
Alternative using ANSI escape codes
printf '\033[2J\033[H'
说明
clear clears the terminal screen if this is possible, including its scrollback buffer (if the extended E3 capability is defined). It looks in the environment for the terminal type given by the environment variable TERM and then queries the terminfo database to determine how to clear the screen. The command outputs escape sequences that instruct the terminal emulator to clear the visible screen area and, by default, the scrollback buffer as well. This is equivalent to pressing Ctrl+L in many shells, though Ctrl+L typically only clears the visible portion without affecting scrollback. The clear command is useful for privacy (removing sensitive output from view), reducing visual clutter during long terminal sessions, and resetting the terminal to a known state.
参数
- -T _type_
- Specify the terminal type to use instead of $TERM
- -V
- Print version information and exit
- -x
- Don't attempt to clear the terminal's scrollback buffer
FAQ
What is the clear command used for?
clear clears the terminal screen if this is possible, including its scrollback buffer (if the extended E3 capability is defined). It looks in the environment for the terminal type given by the environment variable TERM and then queries the terminfo database to determine how to clear the screen. The command outputs escape sequences that instruct the terminal emulator to clear the visible screen area and, by default, the scrollback buffer as well. This is equivalent to pressing Ctrl+L in many shells, though Ctrl+L typically only clears the visible portion without affecting scrollback. The clear command is useful for privacy (removing sensitive output from view), reducing visual clutter during long terminal sessions, and resetting the terminal to a known state.
How do I run a basic clear example?
Run `clear` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -T _type_ do in clear?
Specify the terminal type to use instead of $TERM