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

head tail

head 和 tail 命令详解


命令简介

head 用于输出文件开头部分的内容,默认显示前 10 行

使用语法

head [选项]... [文件]...

选项说明

选项 说明
-c, --bytes=[-]NUM 输出文件的前 NUM 个字节;带 - 时输出除最后 NUM 字节外的所有内容
-n, --lines=[-]NUM 输出前 NUM 行(默认 10 行);带 - 时输出除最后 NUM 行外的所有内容
-q, --quiet, --silent 不显示文件名头(多文件时)
-v, --verbose 总是显示文件名头
-z, --zero-terminated 以 NUL 字符而非换行符作为行分隔符
--help 显示帮助信息
--version 显示版本信息

NUM 后缀说明


二、tail 命令

命令简介

tail 用于输出文件末尾部分的内容,默认显示最后 10 行。特别适合查看日志文件的最新内容。

使用语法

tail [选项]... [文件]...

选项说明

选项 说明
-c, --bytes=[+]NUM 输出最后 NUM 个字节;使用 -c +NUM 从第 NUM 个字节开始输出
`-f, --follow={name descriptor}`
-F 等同于 --follow=name --retry(智能追踪文件名)
-n, --lines=[+]NUM 输出最后 NUM 行(默认 10 行);使用 -n +NUM 从第 NUM 行开始输出
--max-unchanged-stats=N 配合 --follow=name,文件大小不变 N 次后重新打开检查
--pid=PID 配合 -f,当指定 PID 进程结束时终止 tail
-q, --quiet, --silent 不显示文件名头(多文件时)
--retry 文件无法访问时持续重试打开
-s, --sleep-interval=N 配合 -f,每次迭代间隔 N 秒(默认 1.0)
-v, --verbose 总是显示文件名头
-z, --zero-terminated 以 NUL 字符而非换行符作为行分隔符
--help 显示帮助信息
--version 显示版本信息

关于 -f 的说明


三、head 常用案例

1. 查看文件前 10 行(默认)

head file.txt

2. 查看前 20 行

head -n 20 file.txt

3. 查看前 100 个字节

head -c 100 file.txt

4. 查看除最后 5 行外的所有内容

head -n -5 file.txt

5. 查看除最后 100 字节外的所有内容

head -c -100 file.txt

6. 查看多个文件(显示文件名头)

head file1.txt file2.txt
# 输出:
# ==> file1.txt <==
# ...内容...
# ==> file2.txt <==
# ...内容...

7. 查看多个文件,不显示文件名头

head -q file1.txt file2.txt

8. 查看 CSV 表头

head -n 1 data.csv

9. 查看系统进程列表的前 5 个

ps aux | head -n 5

10. 查看目录下最大文件的前几行(组合用法)

ls -la | sort -k5 -rn | head -n 5

四、tail 常用案例

1. 查看文件最后 10 行(默认)

tail file.txt

2. 查看最后 20 行

tail -n 20 file.txt

3. 从第 100 行开始显示到末尾

tail -n +100 file.txt

4. 实时追踪日志(最常用)

tail -f /var/log/syslog
# 按 Ctrl+C 退出

5. 智能追踪(追踪文件名,适合日志轮转)

tail -F /var/log/nginx/access.log
# 即使日志被轮转重命名,仍继续追踪 access.log

6. 实时查看并过滤

tail -f /var/log/syslog | grep ERROR

7. 查看最后 50 个字节

tail -c 50 file.txt

8. 从第 100 个字节开始显示

tail -c +100 file.txt

9. 监控多个日志文件

tail -f /var/log/syslog -f /var/log/nginx/access.log
# 或
tail -f /var/log/syslog /var/log/nginx/access.log

10. 进程结束后停止追踪

tail -f --pid=1234 log.txt
# 当 PID 1234 的进程终止时,tail 自动退出

11. 每 2 秒刷新一次

tail -f -s 2 log.txt

五、head 和 tail 对比

特性 head tail
默认显示 前 10 行 后 10 行
实时追踪 ✅ (-f/-F)
从指定位置开始 仅支持 -n -NUM(排除末尾) -n +NUM(从第 N 行开始)
查看文件头 ✅ 常用
查看文件尾 ✅ 常用
监控日志 ✅ 最常用
进程关联 ✅ (--pid)
重试机制 ✅ (--retry)
查看压缩文件 需配合 zcat 需配合 zcat

六、组合命令使用

1. 查看文件中间部分(取头尾组合)

# 查看文件的第 50 到 80 行
head -n 80 file.txt | tail -n 31

# 或
tail -n +50 file.txt | head -n 31

2. 查看目录下最新修改的 5 个文件

ls -lt | head -n 6

3. 查看目录下最大的 5 个文件

ls -laS | head -n 6

4. 实时监控并显示行号

tail -f log.txt | cat -n

5. 查看日志的错误信息并实时追踪

tail -f app.log | grep -i error

6. 查看多个日志文件的最新内容

tail -n 20 /var/log/*.log

7. 从日志末尾查找特定内容(逆序搜索)

tac log.txt | grep "ERROR" | head -n 10
# tac 反向输出,然后取前 10 个错误

8. 监控日志,忽略重复行

tail -f log.txt | uniq

9. 查看文件大小并实时监控

ls -lh log.txt && tail -f log.txt

10. 生成并实时查看输出

seq 1 1000 | tee >(tail -f) | head -n 20
# 显示前 20 行,同时监控后续输出

11. 查看日志的请求频率(实时统计)

tail -f access.log | cut -d' ' -f1 | uniq -c

七、实际场景应用

场景1:查看配置文件

head -n 30 /etc/nginx/nginx.conf    # 看配置头部
tail -n 30 /etc/nginx/nginx.conf    # 看配置尾部

场景2:查看日志文件

# 查看最新 100 行
tail -n 100 /var/log/syslog

# 实时监控
tail -f /var/log/syslog

# 实时监控并高亮错误
tail -f /var/log/syslog | grep --color=auto ERROR

场景3:数据处理

# 查看 CSV 文件表头
head -n 1 data.csv

# 跳过表头查看数据
tail -n +2 data.csv

# 查看第 11-20 行(跳过表头)
tail -n +2 data.csv | head -n 10

场景4:系统监控

# 查看内存占用最高的 5 个进程
ps aux --sort=-%mem | head -n 6

# 查看 CPU 占用最高的 5 个进程
ps aux --sort=-%cpu | head -n 6

# 实时查看进程变化
watch 'ps aux | head -n 10'

八、快速参考表

需求 命令
查看文件开头 head file.txt
查看文件结尾 tail file.txt
查看前 N 行 head -n N file.txt
查看后 N 行 tail -n N file.txt
从第 N 行开始 tail -n +N file.txt
查看除末尾 N 行 head -n -N file.txt
实时监控日志 tail -f log.txt
智能追踪日志(轮转) tail -F log.txt
查看字节数 head -c 100 / tail -c 100
查看中间行 `head -n M

九、小技巧

1. 设置别名

# 添加到 ~/.rc
alias t='tail -f'
alias h='head -n 20'

2. 使用 tailf 命令(某些系统)

tailf /var/log/syslog   # 类似 tail -f,但更省资源

3. 搭配 watch 命令定期查看

watch -n 5 'tail -n 20 log.txt'   # 每5秒刷新显示最后20行

4. 文件编码检测

head -n 1 file.txt | od -c   # 查看文件第一行的十六进制

Attached Files

Loading attached files...
Search Results