Search

Linux find command

Search a directory tree by name, type, age, and other conditions.

Availability: Common Linux commands; shell built-ins and external implementations may differ by distribution.中文

Syntax

find [STARTING-POINT...] [EXPRESSION]

Examples

Find regular files with a .conf name below the current directory.

find . -type f -name '*.conf'

Find files modified within the last seven 24-hour periods.

find /var/log -type f -mtime -7

Parameters, options and clauses

Option / clauseDescription
-name PATTERNMatch a filename pattern (case-sensitive).
-iname PATTERNMatch a filename pattern without case sensitivity.
-type TYPEMatch a type such as f (file), d (directory) or l (symlink).
-maxdepth NDescend at most N directory levels.
-mtime NMatch by modification age in 24-hour periods.
-size SIZEMatch files by size, such as +100M or -1k.
-exec COMMAND {} \;Run a command for each match; {} represents the path.
-print0Print paths separated by NUL for safe pipelines.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory