Create New Document

The title of your document (will be displayed as H1)
URL-friendly name (no spaces, use dashes)
Path where to create document (optional, use forward slashes to create subdirectories)

Move/Rename Document

Current location of the document
New path for the document (including the slug)
This only changes the document's path. It does not modify the document's title (H1 heading).

Delete Document

Are you sure you want to delete this document? This action cannot be undone.

Warning: If this is a folder, all contents including subfolders and documents will be deleted.

Message

Message content goes here.

Confirm Action

Are you sure?

Attachments

Allowed file types: jpg, jpeg, png, gif, svg, webp, txt, log, csv, sfd, zip, pdf, docx, xlsx, pptx, mp4 (Max: 10MB)

Document Files

Loading attached files...

Document History

Previous Versions

Loading versions...

Preview

Select a version to preview

Wiki Settings

Language for the user interface
Number of versions to keep per document. Set to 0 to disable versioning.
Maximum allowed file size for uploads in MB.

User Management

Add New User

Leave empty to keep current password
Users with these groups can access restricted sections.

Define path-based access rules for sections of your wiki, then assign users to groups in the Users tab. Rules are evaluated in order. First match wins.

Active Rules

Import markdown files from a ZIP archive. Files will be processed and stored in the appropriate document structure. Directory structure in the ZIP (category/subcategory) will be preserved in the wiki.

Upload a ZIP file containing markdown (.md) files to import.

Create and manage backups of your wiki data. Backups include all documents, images, and configuration files.

Available Backups

Loading backups...

Add/Edit Access Rule

Selected: /

Add Column

Banner

clear

clear 命令完全指南

clear 是 Linux 中最简单的终端清屏命令,用于清除当前终端屏幕上的所有内容,将光标移动到屏幕左上角。


一、命令简介

基本功能

clear 命令会清空终端屏幕,并将命令提示符移到屏幕顶部。

提示:clear 是最常用的清屏命令,快捷键 Ctrl+L 清屏

使用语法

clear [选项]

选项说明

选项 说明
-T TERM 指定终端类型,替代 $TERM 环境变量
-V 显示 curses 库版本信息
-x 不清除滚动缓冲区(保留滚动历史)

二、常用案例

1. 基本清屏

clear
# 清除当前终端所有内容,光标移到左上角

2. 不清除滚动缓冲区

clear -x
# 清除屏幕可见区域,但保留滚动历史(可以用鼠标滚轮或 PageUp 查看之前内容)

3. 查看版本信息

clear -V
# 输出类似:clear (ncurses 6.2.20200212)

4. 指定终端类型

clear -T xterm-256color
# 为特定终端类型执行清屏

三、其他清屏方式对比

1. 使用 Ctrl+L 快捷键

# 在任何终端中按下 Ctrl+L
# 效果等同于 clear,但不会清除滚动缓冲区

2. 使用 reset 命令

reset
# 完全重置终端,清除屏幕并重置所有终端设置
# 当终端显示混乱时特别有用

3. 使用 tput 命令

tput clear
# 使用 terminfo 数据库的 clear 能力
# 效果等同于 clear

4. 使用转义序列

printf "\033c"          # 重置终端(等同于 reset)
printf "\033[2J\033[H"  # 清屏并将光标移到左上角
echo -e "\033[2J\033[H"

四、常用组合场景

1. 在脚本中清屏

#!/bin/
# 脚本开始时清屏
clear
echo "Welcome to the script"

2. 循环清屏(动态显示)

#!/bin/
# 显示实时进度
while true; do
    clear
    date
    uptime
    sleep 1
done

3. 清屏后显示信息

clear && echo "Screen cleared! Ready to work."

4. 创建别名

# 添加到 ~/.rc
alias c='clear'
alias cls='clear'
alias cl='clear -x'    # 保留滚动历史

# 使用
c          # 清屏
cl         # 清屏但保留滚动历史

5. 清屏并显示系统信息

clear && echo "=== System Information ===" && date && uptime

6. 清屏并执行其他命令

clear; ls -la          # 清屏后显示目录列表
clear && pwd           # 清屏后显示当前目录

五、clear 与其他清屏方式的区别

命令 清屏 清除滚动缓冲区 重置终端 使用场景
clear ✅(默认) 日常清屏
clear -x 保留历史记录
Ctrl+L 快速清屏
reset 终端显示混乱时
tput clear 脚本中使用
printf "\033c" 完整重置

六、实际应用场景

场景1:监控脚本

#!/bin/
# 实时监控系统状态
while true; do
    clear
    echo "=== System Monitor ==="
    echo "Time: $(date)"
    echo "---"
    echo "CPU Usage:"
    top -bn1 | head -5
    echo "---"
    echo "Memory Usage:"
    free -h
    sleep 2
done

场景2:菜单程序

#!/bin/
# 显示菜单前清屏
show_menu() {
    clear
    echo "========================"
    echo "      MAIN MENU"
    echo "========================"
    echo "1. Option One"
    echo "2. Option Two"
    echo "3. Option Three"
    echo "4. Exit"
    echo "========================"
    echo -n "Enter your choice: "
}

场景3:进度显示

#!/bin/
# 动态显示进度条
for i in {1..20}; do
    clear
    echo "Processing: $i/20"
    echo -n "["
    printf '%0.s#' $(seq 1 $i)
    printf '%0.s-' $(seq 1 $((20-i)))
    echo "]"
    sleep 0.5
done

场景4:清屏后显示当前目录

# 添加到 ~/.rc 自定义命令
cls() {
    clear
    echo "Current directory: $(pwd)"
    echo "---"
    ls -la
}

七、进阶用法

1. 使用 clear 配合 trap(退出时清屏)

#!/bin/
# 脚本退出时清屏
trap clear EXIT
# 脚本内容...

2. 使用 stty 配合清屏

# 在清屏时禁用回显(安全性)
stty -echo
clear
stty echo

3. 清屏并清除终端历史

clear && history -c
# 清屏并清除命令历史

4. 远程 SSH 清屏

# 在 SSH 连接后自动清屏
ssh user@host -t "clear; "

八、常见问题

1. clear 无效?

# 检查终端类型
echo $TERM

# 尝试使用 tput
tput clear

# 使用转义序列
echo -e "\033[2J\033[H"

2. 清屏后还能看到之前内容?

# 使用默认 clear(会清除滚动缓冲区)
clear

# 而不是 clear -x

3. Windows 系统中的清屏

# Windows CMD
cls

# Windows PowerShell
Clear-Host
# 或
cls

# Git  / MSYS2
clear
# 或
printf "\033c"

九、快速参考表

需求 命令
清屏 clear
清屏(保留历史) clear -x
快捷键清屏 Ctrl+L
完整重置终端 reset
脚本中清屏 tput clear
查看版本 clear -V
创建别名 alias c='clear'

十、总结

clear 命令虽然简单,但在日常终端使用中非常实用:

  1. 提高可读性:清除杂乱输出,重新开始
  2. 脚本美化:在交互式脚本中提供清晰的界面
  3. 演示效果:配合循环实现动态显示
  4. 组合使用:与其他命令结合,提供更好的用户体验

推荐别名配置

# 添加到 ~/.rc
alias c='clear'
alias cls='clear'
alias cl='clear -x'          # 保留滚动历史
alias clr='reset'            # 完整重置终端

常用组合命令示例

# 1. 清屏并显示日期时间
clear && date

# 2. 清屏并显示目录内容
clear; ls -la

# 3. 清屏并进入 Python 交互环境
clear && python3

# 4. 清屏后显示帮助信息
clear && man grep

# 5. 循环清屏显示系统状态
watch -n 1 clear && date

# 6. 清屏并执行多个命令
clear && echo "System Info:" && uname -a && df -h

# 7. 清屏并保持(在脚本中使用)
#!/bin/
clear
echo "Press any key to continue..."
read -n1
clear

Attached Files

Loading attached files...
Search Results