← 返回命令列表

Linux command

find 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Find files by

find [path] -name "[*.txt]"

Find directories

find [path] -type d -name "[dirname]"

Find and delete

find [path] -name "[*.tmp]" -delete

Find by modification

find [path] -mtime -[7]

Find and execute

find [path] -name "[*.log]" -exec rm {} \;

说明

find searches directory trees for files matching criteria. It's one of Unix's most powerful utilities, combining searching with file operations through -exec. The tool evaluates expressions left to right, short-circuiting with -a (and) and -o (or). Actions like -print, -delete, and -exec operate on matches. find's flexibility handles complex queries combining name patterns, timestamps, sizes, permissions, and ownership.

参数

-name _PATTERN_
Match filename pattern (glob).
-iname _PATTERN_
Case-insensitive name match.
-type _TYPE_
File type: f (file), d (directory), l (link).
-mtime _N_
Modified N days ago.
-size _N_
File size (c bytes, k KB, M MB).
-exec _CMD_ {} \;
Execute command on results.
-delete
Delete matched files.
-maxdepth _N_
Maximum directory depth.
--help
Display help information.

FAQ

What is the find command used for?

find searches directory trees for files matching criteria. It's one of Unix's most powerful utilities, combining searching with file operations through -exec. The tool evaluates expressions left to right, short-circuiting with -a (and) and -o (or). Actions like -print, -delete, and -exec operate on matches. find's flexibility handles complex queries combining name patterns, timestamps, sizes, permissions, and ownership.

How do I run a basic find example?

Run `find [path] -name "[*.txt]"` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -name _PATTERN_ do in find?

Match filename pattern (glob).