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

tee

tee 命令完全指南

tee 命令用于同时将数据输出到文件并显示在屏幕上。就像字母 T 一样,数据流被分成两路。


一、命令简介

基本功能

使用语法

命令 | tee [选项] 文件名...

二、选项说明

选项 说明
-a, --append 追加到文件末尾(不覆盖原内容)
-i, --ignore-interrupts 忽略中断信号(Ctrl+C)
--help 显示帮助信息
--version 显示版本信息

三、常用案例

1. 基本用法:显示并保存

# 查看文件内容的同时保存
cat file.txt | tee copy.txt

# 查看文件并显示行号
nl file.txt | tee numbered.txt

2. 命令行输出保存并查看

# 查看目录列表,同时保存到文件
ls -la | tee listing.txt

# 查看系统信息,同时保存
uname -a | tee sysinfo.txt

3. 追加到文件(-a 选项)

# 追加内容,不覆盖
echo "新行" | tee -a log.txt

# 追加目录列表到文件
ls | tee -a filelist.txt

4. 同时写入多个文件

# 同时保存到多个文件
echo "重要信息" | tee file1.txt file2.txt file3.txt

# 同时显示并保存多个日志
date | tee log1.txt log2.txt log3.txt

5. 结合 sudo 写入需要权限的文件

# 写入系统配置文件(需要 root 权限)
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf

# 追加到系统文件
echo "新配置" | sudo tee -a /etc/hosts

6. 在脚本中记录操作

#!/bin/
# 记录脚本执行过程
echo "开始执行: $(date)" | tee -a script.log
./run_task.sh | tee -a script.log
echo "执行完成: $(date)" | tee -a script.log

7. 管道中的使用

# 查看并统计行数
cat file.txt | tee copy.txt | wc -l

# 查看并搜索
dmesg | tee kernel.log | grep error

# 查看并压缩
ps aux | tee process.txt | grep root

8. 实时监控并记录

# 监控日志并保存
tail -f /var/log/syslog | tee syslog_copy.txt

# 监控系统负载
vmstat 1 | tee vmstat.log

9. 忽略中断信号(-i)

# 按 Ctrl+C 时不会中断 tee,会继续处理
tee -i log.txt
# 输入内容,Ctrl+C 不会停止(Ctrl+D 才退出)

四、常见使用场景

场景1:写入需要 sudo 权限的文件

# ❌ 错误写法(重定向没有权限)
echo "配置内容" > /etc/myconfig.conf
# Permission denied

# ✅ 正确写法
echo "配置内容" | sudo tee /etc/myconfig.conf

# 追加
echo "新配置" | sudo tee -a /etc/myconfig.conf

场景2:同时查看和保存命令输出

# 查看磁盘使用,同时保存
df -h | tee disk_usage.txt

# 查看内存信息,同时保存
free -h | tee -a system_info.txt

# 查看进程信息,同时保存
ps aux | tee process_list.txt

场景3:备份命令输出

# 执行命令,保存输出,同时显示
./deploy.sh 2>&1 | tee deploy.log

# 查看错误日志
./build.sh 2>&1 | tee build.log

场景4:配置文件的快速修改

# 修改 hosts 文件
echo "127.0.0.1 myapp.local" | sudo tee -a /etc/hosts

# 修改 sysctl 配置
echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf

# 修改 limits 配置
echo "* soft nofile 65535" | sudo tee -a /etc/security/limits.conf

场景5:数据备份和传输

# 查看并备份
cat data.txt | tee backup.txt | gzip > data.txt.gz

# 查看并处理
cat raw.csv | tee backup.csv | sort | uniq > processed.csv

五、管道中的数据流向

# 基本流向
echo "hello" | tee file.txt
# ┌─────────┐     ┌─────┐     ┌──────────┐
# │ echo    │────▶│ tee │────▶│ 屏幕     │
# └─────────┘     └─────┘     └──────────┘
#                      │
#                      ▼
#                  ┌──────────┐
#                  │ file.txt │
#                  └──────────┘

# 多个管道
echo "hello" | tee file.txt | wc -l
# ┌─────────┐     ┌─────┐     ┌───────┐
# │ echo    │────▶│ tee │────▶│ wc -l │
# └─────────┘     └─────┘     └───────┘
#                      │
#                      ▼
#                  ┌──────────┐
#                  │ file.txt │
#                  └──────────┘

六、常见问题解决

1. 写入没有权限的文件

# 使用 sudo
echo "内容" | sudo tee /etc/config.conf

2. 追加而不是覆盖

# 使用 -a 选项
echo "新内容" | sudo tee -a /etc/config.conf

3. 同时写入 stderr 和 stdout

# 将错误也一起保存
./script.sh 2>&1 | tee output.log

4. 不需要屏幕显示

# 只保存到文件(不显示)
echo "内容" | tee file.txt > /dev/null

七、对比重定向

命令 屏幕显示 写入文件 适用场景
echo "a" > file 只需要保存
`echo "a" tee file`
`echo "a" tee -a file` ✅(追加)
`echo "a" sudo tee file` ✅(root)

八、快速参考表

需求 命令
显示并保存 `command
追加到文件 `command
写入多个文件 `command
需要 root 权限 `echo "x"
需要 root 追加 `echo "x"
显示但不需要保存 command(不用 tee)
保存但不显示 command > file.txt

九、实用组合

# 1. 查看系统信息并保存
uname -a | tee sysinfo.log
dmesg | tee dmesg.log

# 2. 监控日志并保存
tail -f /var/log/nginx/access.log | tee access.log

# 3. 安装软件记录输出
apt-get install nginx 2>&1 | tee install.log

# 4. 查看并统计
cat bigfile.txt | tee copy.txt | wc -l

# 5. 备份和压缩
cat data.sql | tee backup.sql | gzip > data.sql.gz

总结

tee 的核心作用:

  1. 同时查看和保存输出
  2. 写入多个文件(包括需要 root 权限的文件)
  3. 追加内容而不覆盖
  4. 管道中间传递数据

最常用场景:

# 写入系统配置文件
echo "配置" | sudo tee /etc/file.conf

# 查看命令输出并记录日志
command | tee log.txt

Attached Files

Loading attached files...
Search Results