文件操作CLI Manual
$find
根据文件名、类型、大小或修改时间在目录层级中高效搜索文件与目录。
命令语法POSIX Standard
find [PATH] [OPTIONS] [EXPRESSION]在交互式终端沙盒中实时运行
无需安装的客户端实时仿真环境。
bash — terminal
AST Sandbox (Free)
概述与工作原理
find 命令是 Linux 系统中最核心、最强大的文件查找工具。它直接在文件系统中进行实时递归扫描,支持通配符、修改时间、文件大小及权限等全方位条件过滤。
常用参数与选项说明
| Flag / Option | Description |
|---|---|
| -name [pattern] | Search for files matching the specified filename or wildcard pattern (case-sensitive). |
| -iname [pattern] | Search for files matching the pattern ignoring case distinctions. |
| -type [f|d|l] | Filter results by file type: f (regular file), d (directory), l (symbolic link). |
| -size [+|-][n] | Search by file size: +10M (larger than 10MB), -1k (smaller than 1KB). |
| -mtime [n] | Find files modified n*24 hours ago (+7 for older than a week, -1 for last 24h). |
| -exec [cmd] {} \; | Execute a specific shell command on each matching file found. |
实际生产案例与代码范例
#1Find files by exact name or extension
find /var/log -name "*.log"Recursively scans the /var/log directory for all files ending with the .log extension.
#2Find all directories in the home folder
find /home/user -type dFilters and outputs only directory paths inside the user home folder.
#3Find files modified in the last 24 hours
find . -type f -mtime -1Locates recently created or modified files in the current working directory.