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

find

find 命令完全指南

find 是 Linux 中最强大的文件搜索工具,可以在指定目录下根据各种条件搜索文件和目录,并执行相应操作。


一、命令语法

find [路径...] [表达式]

基本结构

find [搜索起始目录] [匹配条件] [执行动作]

二、表达式分类

1. 操作符(Operators)

操作符 说明 优先级
( EXPR ) 括号,改变优先级 最高
! EXPR / -not EXPR 取反 最高
EXPR1 -a EXPR2 / -and 与(默认隐含)
EXPR1 -o EXPR2 / -or
EXPR1 , EXPR2 逗号,分别执行 最低

2. 位置选项(Positional Options)

选项 说明
-daystart 从今天开始计算时间(用于时间测试)
-follow 跟随符号链接
-regextype 指定正则表达式类型

3. 普通选项(Normal Options)

选项 说明
-depth 先处理子目录,再处理目录本身
-maxdepth LEVELS 最大搜索深度
-mindepth LEVELS 最小搜索深度
-mount / -xdev 不跨越文件系统
-noleaf 不优化搜索(某些文件系统)
-ignore_readdir_race 忽略读取目录时的竞争条件

4. 测试条件(Tests)

时间相关

测试 说明
-amin N N 分钟前访问过
-anewer FILE 比 FILE 更晚访问
-atime N N*24 小时前访问过
-cmin N N 分钟前状态改变
-cnewer FILE 比 FILE 更晚改变状态
-ctime N N*24 小时前状态改变
-mmin N N 分钟前修改过
-mtime N N*24 小时前修改过
-newer FILE 比 FILE 更新
-used N 文件被访问后 N 天被修改

文件属性相关

测试 说明
-empty 空文件或空目录
-false 始终为假
-true 始终为真
-fstype TYPE 文件系统类型
-gid N 组 ID
-group NAME 组名
-uid N 用户 ID
-user NAME 用户名
-links N 硬链接数
-size N[bcwkMG] 文件大小
-type [bcdpflsD] 文件类型
-perm [-/]MODE 权限模式
-readable 可读
-writable 可写
-executable 可执行
-nouser 没有所属用户
-nogroup 没有所属组

文件名相关

测试 说明
-name PATTERN 文件名匹配(区分大小写)
-iname PATTERN 文件名匹配(不区分大小写)
-lname PATTERN 符号链接目标匹配
-ilname PATTERN 符号链接目标匹配(不区分大小写)
-path PATTERN 路径匹配
-wholename PATTERN 完整路径匹配
-ipath PATTERN 路径匹配(不区分大小写)
-iwholename PATTERN 完整路径匹配(不区分大小写)
-regex PATTERN 正则表达式匹配路径
-iregex PATTERN 正则表达式匹配路径(不区分大小写)
-inum N inode 号
-xtype [bcdpfls] 检查符号链接指向的类型

上下文相关(SELinux)

测试 说明
-context CONTEXT SELinux 上下文

5. 动作(Actions)

动作 说明
-delete 删除找到的文件
-print 打印路径(默认)
-print0 打印路径,以 NUL 分隔
-printf FORMAT 自定义格式打印
-fprint FILE 打印到文件
-fprint0 FILE 打印到文件(NUL 分隔)
-fprintf FILE FORMAT 自定义格式打印到文件
-ls 以 ls -l 格式显示
-fls FILE 以 ls -l 格式输出到文件
-prune 不进入目录
-quit 找到第一个匹配后退出
-exec COMMAND ; 对每个结果执行命令
-exec COMMAND {} + 批量执行命令(更高效)
-execdir COMMAND ; 在文件所在目录执行
-execdir COMMAND {} + 批量在文件所在目录执行
-ok COMMAND ; 执行前提示确认
-okdir COMMAND ; 在文件所在目录执行前提示

三、常用案例

基础搜索

1. 列出当前目录所有文件

find .              # 列出所有文件和目录
find                # 默认当前目录
find . -print       # 同上,-print 是默认动作

2. 按文件名搜索

# 精确匹配文件名
find /etc -name "passwd"

# 不区分大小写
find /home -iname "readme.txt"

# 通配符匹配
find /var -name "*.log"
find /usr -name "conf*"
find /opt -name "*test*"

3. 按文件类型搜索

find / -type f              # 普通文件
find / -type d              # 目录
find / -type l              # 符号链接
find / -type b              # 块设备
find / -type c              # 字符设备
find / -type s              # socket 文件
find / -type p              # 管道文件

4. 按文件大小搜索

find / -size 100M           # 恰好 100MB
find / -size +100M          # 大于 100MB
find / -size -1M            # 小于 1MB
find / -size 0              # 空文件
find / -size +1G -size -2G  # 1GB 到 2GB 之间

# 单位:b(512字节块), c(字节), w(2字节字), k(KB), M(MB), G(GB)

时间搜索

5. 按修改时间搜索

# 修改时间(mtime - 文件内容修改)
find /var -mtime 0          # 今天修改的(24小时内)
find /var -mtime -7         # 7天内修改
find /var -mtime +30        # 30天前修改
find /var -mmin -10         # 10分钟内修改

# 访问时间(atime - 文件被读取)
find / -atime -3            # 3天内访问过

# 状态改变时间(ctime - 权限/所有者等改变)
find / -ctime -1            # 1天内状态改变

6. 查找比指定文件更新的文件

find / -newer /tmp/reference.txt
find / -anewer /tmp/ref.txt   # 访问时间更新
find / -cnewer /tmp/ref.txt   # 状态改变时间更新

权限搜索

7. 按权限搜索

find / -perm 644            # 精确匹配权限
find / -perm -644           # 至少包含这些权限(如 644, 755 都匹配)
find / -perm /644           # 任意匹配这些权限位
find / -perm +644           # 旧语法,等同于 /644
find / ! -perm 644          # 不是 644 权限

8. 查找可读/可写/可执行文件

find / -readable            # 可读文件
find / -writable            # 可写文件
find / -executable          # 可执行文件
find / -readable -and -writable   # 可读且可写

9. 查找属主/属组

find /home -user john       # 属于用户 john
find / -group admin         # 属于组 admin
find / -nouser              # 没有属主的文件(孤儿文件)
find / -nogroup             # 没有属组的文件

深度控制

10. 限制搜索深度

find / -maxdepth 2 -name "*.conf"   # 最多深入2层
find / -mindepth 3 -type f          # 至少深入3层
find / -maxdepth 1 -type d          # 只看当前目录下的目录

组合条件

11. 逻辑运算

# AND(默认)
find / -name "*.txt" -type f

# OR
find / -name "*.jpg" -o -name "*.png"

# NOT
find / ! -name "*.log"

# 组合复杂条件
find / \( -name "*.txt" -o -name "*.md" \) -size +1M

执行动作

12. 执行命令

# 删除找到的文件
find /tmp -name "*.tmp" -delete

# 对每个文件执行命令(使用 {} 代表文件)
find / -name "*.conf" -exec ls -l {} \;

# 批量执行(更高效,一次传递多个文件)
find / -name "*.txt" -exec grep "error" {} +

# 执行命令前确认
find / -name "*.tmp" -ok rm {} \;

13. 在文件所在目录执行

# 进入文件所在目录执行
find / -name "*.jpg" -execdir convert {} {}.png \;

14. 自定义输出格式

# 打印详细信息
find / -name "*.log" -ls

# 自定义格式
find / -name "*.txt" -printf "%p - %s bytes\n"
# %p 路径, %s 大小, %f 文件名, %m 权限, %u 用户, %g 组

15. 找到第一个即退出

find / -name "core" -quit

四、常用组合命令

1. 查找并删除大文件

find /var -type f -size +100M -exec rm -f {} \;
# 或更安全:先查看
find /var -type f -size +100M -exec ls -lh {} \;

2. 查找并压缩日志文件

find /var/log -name "*.log" -mtime +30 -exec gzip {} \;

3. 查找并修改权限

# 查找脚本文件并添加执行权限
find /scripts -name "*.sh" -exec chmod +x {} \;

# 批量修改目录权限为755,文件权限为644
find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;

4. 统计文件数量

find / -type f | wc -l          # 总文件数
find / -type d | wc -l          # 总目录数
find . -name "*.txt" | wc -l    # .txt 文件数

5. 查找并删除空目录

find / -type d -empty -delete

6. 查找最近修改的文件(前10个)

find / -type f -mtime -1 -printf "%T@ %p\n" | sort -rn | head -10

7. 查找并替换文件内容

# 在找到的文件中替换内容
find / -name "*.html" -exec sed -i 's/old/new/g' {} \;

8. 查找重复文件(基于大小和 MD5)

# 先找大小相同
find . -type f -exec md5sum {} \; | sort | uniq -w32 -d

9. 排除特定目录搜索

find / -path /proc -prune -o -name "*.conf" -print
find / -path /sys -prune -o -type f -name "*.log" -print

10. 查找并移动文件

find /source -name "*.pdf" -exec mv {} /dest/ \;

11. 查找并复制到新位置(保留目录结构)

find /source -name "*.jpg" -exec cp --parents {} /backup/ \;

12. 实时监控文件变化

# 结合 watch 命令
watch -n 1 'find /var/log -mmin -1 -type f'

13. 查找符号链接及其目标

find / -type l -ls
find / -type l -exec ls -l {} \;

14. 查找并打包

find /data -name "*.log" -mtime +7 | tar -czf old_logs.tar.gz -T -

15. 查找特殊权限文件

find / -perm -4000 -type f      # SUID 文件
find / -perm -2000 -type f      # SGID 文件
find / -perm -1000 -type f      # Sticky bit 文件
find / -perm -1000 -type d      # Sticky bit 目录(如 /tmp)

五、高级技巧

1. 使用正则表达式

# 查找以数字开头的文件
find . -regex ".*/[0-9].*"

# 查找特定日期格式的文件
find . -regex ".*/[0-9]{4}-[0-9]{2}-[0-9]{2}.*"

2. 调试 find 命令

find -D tree / -name "*.txt"    # 显示搜索树
find -D search / -name "*.txt"  # 显示搜索过程
find -D all / -name "*.txt"     # 显示所有调试信息

3. 并行处理(使用 xargs)

# 更高效地处理大量文件
find / -name "*.txt" -print0 | xargs -0 grep "error"
find / -name "*.log" -print0 | xargs -0 -P 4 gzip
# -P 4 表示使用4个并行进程

4. 优化搜索性能

# 指定深度限制
find / -maxdepth 3 -name "*.conf"

# 先检查文件名,再检查其他条件(更高效)
find / -name "*.log" -type f -size +10M

# 使用 -noleaf 在非 Unix 文件系统上
find /mnt -noleaf -name "*.txt"

六、快速参考表

需求 命令
按文件名搜索 find / -name "filename"
搜索目录 find / -type d -name "dirname"
搜索大文件(>100MB) find / -type f -size +100M
搜索空文件 find / -type f -empty
搜索空目录 find / -type d -empty
搜索最近修改的文件 find / -mtime -1
搜索特定用户文件 find / -user username
搜索特定权限文件 find / -perm 755
删除找到的文件 find / -name "*.tmp" -delete
执行命令 find / -name "*.txt" -exec ls -l {} \;
限制搜索深度 find / -maxdepth 2 -name "*.conf"
排除目录 find / -path /proc -prune -o -name "*.log"
统计文件数 `find / -type f

七、安全注意事项

1. 谨慎使用 -delete

# 先预览再删除
find / -name "*.tmp"           # 先查看
find / -name "*.tmp" -exec ls -l {} \;  # 详细查看
find / -name "*.tmp" -delete   # 确认无误再删除

2. 处理特殊字符文件名

# 使用 -print0 和 xargs -0 处理文件名中的空格
find / -name "*.txt" -print0 | xargs -0 rm -f

3. 避免搜索 / 目录(性能问题)

# 先切换到子目录搜索
cd /var && find . -name "*.log"

# 或限制深度
find / -maxdepth 3 -name "*.conf"

4. 使用 -ok 替代 -exec 测试

find / -name "*.tmp" -ok rm {} \;
# 会提示确认每个操作

八、实战场景

场景1:清理旧日志

# 删除30天前的 .log 文件
find /var/log -name "*.log" -mtime +30 -delete

场景2:查找并修复权限

# 修复家目录权限
find /home -type f -exec chmod 644 {} \;
find /home -type d -exec chmod 755 {} \;

场景3:查找重复文件

# 查找重复文件(基于大小)
find . -type f -exec ls -l {} \; | sort -k5 -n | uniq -D -f4

场景4:查找并归档旧文件

# 归档 90 天前的文件
find /data -mtime +90 -type f | tar -czf archive.tar.gz -T -

场景5:实时日志监控

# 监控最近5分钟修改的日志
watch -n 60 'find /var/log -mmin -5 -type f -ls'

Attached Files

Loading attached files...
Search Results