find command

The find command is one of the most useful Unix and Linux file-search tools. Its syntax can feel different from newer CLI tools because it works more like a small expression language than a simple command [options] [arguments] command.
The basic structure is:
find [where to look] [what to look for] [what to do with it]
If no search path is provided, find starts from the current directory, .. If no action is provided, it prints matching paths.
Anatomy of a find Command
Example:
find . -type f -name "*.log" -print
This means:
.: start in the current directory-type f: match files only-name "*.log": match names ending in.log-print: print the matching paths
The general pattern is:
find path expression action
1. Find Files by Name
Use -name for case-sensitive matching and -iname for case-insensitive matching.
find /var/log -iname "*.log"
Always quote wildcard patterns such as "*.log" so the shell does not expand them before find receives the pattern.
2. Filter by Type
By default, find can return both files and directories. Use -type to narrow the result.
Find directories named config:
find . -type d -name "config"
Find executable files:
find . -type f -perm /a+x
Common -type values:
f: regular file
d: directory
l: symbolic link
3. Find Files by Size
Use -size with + or - to find files larger or smaller than a threshold.
Find files larger than 1 GB in the home directory:
find ~ -type f -size +1G
Common units:
k: kilobytes
M: megabytes
G: gigabytes
Examples:
find . -type f -size +100M
find . -type f -size -10k
4. Find Files by Modification Time
Use -mtime for days and -mmin for minutes.
Find files modified in the last 10 minutes:
find . -type f -mmin -10
Find files modified more than 30 days ago:
find /var/log -type f -mtime +30
Meaning:
-10: less than 10 units ago
+30: more than 30 units ago
30: exactly 30 units, according to find's time rounding rules
5. Execute Commands on Results
Use -exec to run another command against matching files.
Find .bak files and delete them in bulk:
find . -type f -name "*.bak" -exec rm {} +
How it works:
{}is replaced with matching file paths.+groups many matching files into one command where possible.\;runs the command once per file.
Prefer this form for efficiency:
find . -type f -name "*.bak" -exec rm {} +
This form is slower for large result sets:
find . -type f -name "*.bak" -exec rm {} \;
When deleting files, preview the matches first:
find . -type f -name "*.bak" -print
Then run the destructive command only after confirming the result set.
6. Skip Directories with prune
In development projects, find can waste time scanning large directories such as node_modules or .git. Use -prune to skip them.
Search for JavaScript files while skipping node_modules:
find . -path "./node_modules" -prune -o -name "*.js" -print
The logic is:
If the path is ./node_modules, skip it.
Otherwise, find files matching *.js and print them.
Skip both node_modules and .git:
find . \( -path "./node_modules" -o -path "./.git" \) -prune -o -type f -name "*.js" -print
Practical Examples
Find all Markdown files:
find . -type f -name "*.md"
Find all files modified today:
find . -type f -mtime -1
Find empty directories:
find . -type d -empty
Find files larger than 500 MB:
find . -type f -size +500M
Find and rename matching files with another command:
find . -type f -name "*.jpeg" -exec sh -c 'mv "$1" "${1%.jpeg}.jpg"' _ {} \;
Summary
The key to using find well is to think in three parts:
find [where] [match conditions] [action]
Use -type, -name, -iname, -size, and time filters to narrow the result. Use -exec for automation, but preview destructive matches with -print before deleting or modifying files.

find 명령어는 Unix와 Linux에서 가장 유용한 파일 검색 도구 중 하나입니다. 문법은 최신 CLI 도구와 조금 다르게 느껴질 수 있습니다. 단순한 command [options] [arguments] 형식이라기보다 작은 표현식 언어처럼 동작하기 때문입니다.
기본 구조는 다음과 같습니다.
find [where to look] [what to look for] [what to do with it]
검색 경로를 제공하지 않으면 find는 현재 디렉터리인 .에서 시작합니다. 동작을 제공하지 않으면 일치하는 경로를 출력합니다.
find 명령어의 구조
예시:
find . -type f -name "*.log" -print
이 명령은 다음을 의미합니다.
.: 현재 디렉터리에서 시작-type f: 파일만 일치-name "*.log":.log로 끝나는 이름 일치-print: 일치하는 경로 출력
일반적인 패턴은 다음과 같습니다.
find path expression action
1. 이름으로 파일 찾기
대소문자를 구분해 일치시키려면 -name을 사용하고, 대소문자를 구분하지 않으려면 -iname을 사용합니다.
find /var/log -iname "*.log"
"*.log" 같은 와일드카드 패턴은 항상 따옴표로 감싸세요. 그래야 셸이 패턴을 먼저 확장하지 않고 find가 그대로 받을 수 있습니다.
2. 유형으로 필터링하기
기본적으로 find는 파일과 디렉터리를 모두 반환할 수 있습니다. 결과를 좁히려면 -type을 사용합니다.
config라는 이름의 디렉터리 찾기:
find . -type d -name "config"
실행 가능한 파일 찾기:
find . -type f -perm /a+x
자주 쓰는 -type 값:
f: regular file
d: directory
l: symbolic link
3. 크기로 파일 찾기
특정 기준보다 크거나 작은 파일을 찾으려면 -size와 + 또는 -를 함께 사용합니다.
홈 디렉터리에서 1 GB보다 큰 파일 찾기:
find ~ -type f -size +1G
자주 쓰는 단위:
k: kilobytes
M: megabytes
G: gigabytes
예시:
find . -type f -size +100M
find . -type f -size -10k
4. 수정 시간으로 파일 찾기
일 단위는 -mtime, 분 단위는 -mmin을 사용합니다.
최근 10분 안에 수정된 파일 찾기:
find . -type f -mmin -10
30일보다 오래전에 수정된 파일 찾기:
find /var/log -type f -mtime +30
의미:
-10: less than 10 units ago
+30: more than 30 units ago
30: exactly 30 units, according to find's time rounding rules
5. 결과에 명령 실행하기
일치하는 파일에 다른 명령을 실행하려면 -exec를 사용합니다.
.bak 파일을 찾아 한 번에 삭제하기:
find . -type f -name "*.bak" -exec rm {} +
동작 방식:
{}는 일치하는 파일 경로로 대체됩니다.+는 가능하면 여러 일치 항목을 하나의 명령으로 묶습니다.\;는 파일마다 명령을 한 번씩 실행합니다.
효율을 위해 이 형식을 선호하세요.
find . -type f -name "*.bak" -exec rm {} +
이 형식은 결과가 많을 때 더 느립니다.
find . -type f -name "*.bak" -exec rm {} \;
파일을 삭제할 때는 먼저 일치 항목을 미리 확인하세요.
find . -type f -name "*.bak" -print
그런 다음 결과 집합을 확인한 뒤에만 파괴적인 명령을 실행하세요.
6. prune으로 디렉터리 건너뛰기
개발 프로젝트에서 find는 node_modules나 .git처럼 큰 디렉터리를 스캔하느라 시간을 낭비할 수 있습니다. 이런 디렉터리를 건너뛰려면 -prune을 사용합니다.
node_modules를 건너뛰면서 JavaScript 파일 검색하기:
find . -path "./node_modules" -prune -o -name "*.js" -print
로직은 다음과 같습니다.
If the path is ./node_modules, skip it.
Otherwise, find files matching *.js and print them.
node_modules와 .git을 모두 건너뛰기:
find . \( -path "./node_modules" -o -path "./.git" \) -prune -o -type f -name "*.js" -print
실용 예시
모든 Markdown 파일 찾기:
find . -type f -name "*.md"
오늘 수정된 모든 파일 찾기:
find . -type f -mtime -1
빈 디렉터리 찾기:
find . -type d -empty
500 MB보다 큰 파일 찾기:
find . -type f -size +500M
일치하는 파일을 다른 명령으로 이름 변경하기:
find . -type f -name "*.jpeg" -exec sh -c 'mv "$1" "${1%.jpeg}.jpg"' _ {} \;
요약
find를 잘 쓰는 핵심은 세 부분으로 생각하는 것입니다.
find [where] [match conditions] [action]
-type, -name, -iname, -size, 시간 필터를 사용해 결과를 좁히세요. 자동화에는 -exec를 사용하되, 파일을 삭제하거나 수정하기 전에는 -print로 파괴적인 대상 목록을 먼저 확인하세요.

find 命令是 Unix 和 Linux 中最有用的文件搜索工具之一。它的语法可能会让人觉得和较新的 CLI 工具有些不同,因为它更像一个小型表达式语言,而不是简单的 command [options] [arguments] 命令。
基本结构是:
find [where to look] [what to look for] [what to do with it]
如果没有提供搜索路径,find 会从当前目录 . 开始。如果没有提供动作,它会打印匹配的路径。
find 命令的结构
示例:
find . -type f -name "*.log" -print
这表示:
.: 从当前目录开始-type f: 只匹配文件-name "*.log": 匹配以.log结尾的名称-print: 打印匹配路径
通用模式是:
find path expression action
1. 按名称查找文件
使用 -name 进行区分大小写的匹配,使用 -iname 进行不区分大小写的匹配。
find /var/log -iname "*.log"
请始终给 "*.log" 这样的通配符模式加上引号,避免 shell 在 find 接收到模式之前先展开它。
2. 按类型筛选
默认情况下,find 可以返回文件和目录。使用 -type 可以缩小结果范围。
查找名为 config 的目录:
find . -type d -name "config"
查找可执行文件:
find . -type f -perm /a+x
常见的 -type 值:
f: regular file
d: directory
l: symbolic link
3. 按大小查找文件
使用 -size 配合 + 或 -,可以查找大于或小于某个阈值的文件。
在 home 目录中查找大于 1 GB 的文件:
find ~ -type f -size +1G
常见单位:
k: kilobytes
M: megabytes
G: gigabytes
示例:
find . -type f -size +100M
find . -type f -size -10k
4. 按修改时间查找文件
按天使用 -mtime,按分钟使用 -mmin。
查找最近 10 分钟内修改过的文件:
find . -type f -mmin -10
查找 30 天以前修改过的文件:
find /var/log -type f -mtime +30
含义:
-10: less than 10 units ago
+30: more than 30 units ago
30: exactly 30 units, according to find's time rounding rules
5. 对结果执行命令
使用 -exec 可以对匹配文件运行另一个命令。
查找 .bak 文件并批量删除:
find . -type f -name "*.bak" -exec rm {} +
工作方式:
{}会被替换为匹配的文件路径。+会在可能的情况下把多个匹配文件组合到一个命令中。\;会对每个文件单独运行一次命令。
为了效率,优先使用这种形式:
find . -type f -name "*.bak" -exec rm {} +
在结果集很大时,这种形式更慢:
find . -type f -name "*.bak" -exec rm {} \;
删除文件时,请先预览匹配项:
find . -type f -name "*.bak" -print
确认结果集之后,再运行具有破坏性的命令。
6. 使用 prune 跳过目录
在开发项目中,find 可能会花很多时间扫描 node_modules 或 .git 这样的大目录。使用 -prune 可以跳过它们。
在跳过 node_modules 的同时搜索 JavaScript 文件:
find . -path "./node_modules" -prune -o -name "*.js" -print
逻辑是:
If the path is ./node_modules, skip it.
Otherwise, find files matching *.js and print them.
同时跳过 node_modules 和 .git:
find . \( -path "./node_modules" -o -path "./.git" \) -prune -o -type f -name "*.js" -print
实用示例
查找所有 Markdown 文件:
find . -type f -name "*.md"
查找今天修改过的所有文件:
find . -type f -mtime -1
查找空目录:
find . -type d -empty
查找大于 500 MB 的文件:
find . -type f -size +500M
使用另一个命令重命名匹配文件:
find . -type f -name "*.jpeg" -exec sh -c 'mv "$1" "${1%.jpeg}.jpg"' _ {} \;
总结
用好 find 的关键,是按三个部分来思考:
find [where] [match conditions] [action]
使用 -type、-name、-iname、-size 和时间过滤器缩小结果范围。使用 -exec 做自动化,但在删除或修改文件之前,先用 -print 预览具有破坏性的匹配项。

find コマンドは、Unix と Linux で最も便利なファイル検索ツールのひとつです。構文は新しい CLI ツールとは少し違って感じられるかもしれません。単純な command [options] [arguments] 形式というより、小さな式言語のように動作するからです。
基本構造は次のとおりです。
find [where to look] [what to look for] [what to do with it]
検索パスを指定しない場合、find は現在のディレクトリ . から開始します。アクションを指定しない場合は、一致したパスを出力します。
find コマンドの構造
例:
find . -type f -name "*.log" -print
これは次の意味です。
.: 現在のディレクトリから開始-type f: ファイルだけに一致-name "*.log":.logで終わる名前に一致-print: 一致したパスを出力
一般的なパターンは次のとおりです。
find path expression action
1. 名前でファイルを探す
大文字小文字を区別して一致させるには -name、区別しない場合は -iname を使います。
find /var/log -iname "*.log"
"*.log" のようなワイルドカードパターンは必ず引用符で囲みます。そうしないと、find がパターンを受け取る前に shell が展開してしまいます。
2. 種類で絞り込む
デフォルトでは、find はファイルとディレクトリの両方を返すことがあります。結果を絞り込むには -type を使います。
config という名前のディレクトリを探す:
find . -type d -name "config"
実行可能ファイルを探す:
find . -type f -perm /a+x
よく使う -type の値:
f: regular file
d: directory
l: symbolic link
3. サイズでファイルを探す
しきい値より大きい、または小さいファイルを探すには、-size と + または - を組み合わせます。
home ディレクトリで 1 GB より大きいファイルを探す:
find ~ -type f -size +1G
よく使う単位:
k: kilobytes
M: megabytes
G: gigabytes
例:
find . -type f -size +100M
find . -type f -size -10k
4. 更新時刻でファイルを探す
日単位には -mtime、分単位には -mmin を使います。
直近 10 分以内に変更されたファイルを探す:
find . -type f -mmin -10
30 日より前に変更されたファイルを探す:
find /var/log -type f -mtime +30
意味:
-10: less than 10 units ago
+30: more than 30 units ago
30: exactly 30 units, according to find's time rounding rules
5. 結果に対してコマンドを実行する
一致したファイルに別のコマンドを実行するには -exec を使います。
.bak ファイルを探してまとめて削除する:
find . -type f -name "*.bak" -exec rm {} +
仕組み:
{}は一致したファイルパスに置き換えられます。+は可能な場合、複数の一致ファイルをひとつのコマンドにまとめます。\;はファイルごとにコマンドを 1 回実行します。
効率のため、この形式を優先します。
find . -type f -name "*.bak" -exec rm {} +
結果セットが大きい場合、この形式は遅くなります。
find . -type f -name "*.bak" -exec rm {} \;
ファイルを削除するときは、先に一致結果をプレビューします。
find . -type f -name "*.bak" -print
結果セットを確認してから、破壊的なコマンドを実行してください。
6. prune でディレクトリをスキップする
開発プロジェクトでは、find が node_modules や .git のような大きなディレクトリをスキャンして時間を浪費することがあります。これらをスキップするには -prune を使います。
node_modules をスキップしながら JavaScript ファイルを検索する:
find . -path "./node_modules" -prune -o -name "*.js" -print
ロジックは次のとおりです。
If the path is ./node_modules, skip it.
Otherwise, find files matching *.js and print them.
node_modules と .git の両方をスキップする:
find . \( -path "./node_modules" -o -path "./.git" \) -prune -o -type f -name "*.js" -print
実用例
すべての Markdown ファイルを探す:
find . -type f -name "*.md"
今日変更されたすべてのファイルを探す:
find . -type f -mtime -1
空のディレクトリを探す:
find . -type d -empty
500 MB より大きいファイルを探す:
find . -type f -size +500M
一致したファイルを別のコマンドでリネームする:
find . -type f -name "*.jpeg" -exec sh -c 'mv "$1" "${1%.jpeg}.jpg"' _ {} \;
まとめ
find をうまく使う鍵は、3 つの部分で考えることです。
find [where] [match conditions] [action]
-type、-name、-iname、-size、時刻フィルターを使って結果を絞り込みます。自動化には -exec を使えますが、ファイルを削除または変更する前には、-print で破壊的な対象を必ずプレビューしてください。

El comando find es una de las herramientas de búsqueda de archivos más útiles en Unix y Linux. Su sintaxis puede sentirse diferente a la de herramientas CLI más nuevas porque funciona más como un pequeño lenguaje de expresiones que como un simple comando command [options] [arguments].
La estructura básica es:
find [where to look] [what to look for] [what to do with it]
Si no se proporciona una ruta de búsqueda, find empieza desde el directorio actual, .. Si no se proporciona ninguna acción, imprime las rutas que coinciden.
Anatomía de un comando find
Ejemplo:
find . -type f -name "*.log" -print
Esto significa:
.: empezar en el directorio actual-type f: coincidir solo con archivos-name "*.log": coincidir con nombres que terminan en.log-print: imprimir las rutas coincidentes
El patrón general es:
find path expression action
1. Buscar archivos por nombre
Usa -name para coincidencias sensibles a mayúsculas y minúsculas, y -iname para coincidencias insensibles a mayúsculas y minúsculas.
find /var/log -iname "*.log"
Pon siempre entre comillas los patrones con comodines, como "*.log", para que la shell no los expanda antes de que find reciba el patrón.
2. Filtrar por tipo
Por defecto, find puede devolver tanto archivos como directorios. Usa -type para acotar el resultado.
Buscar directorios llamados config:
find . -type d -name "config"
Buscar archivos ejecutables:
find . -type f -perm /a+x
Valores comunes de -type:
f: regular file
d: directory
l: symbolic link
3. Buscar archivos por tamaño
Usa -size con + o - para encontrar archivos mayores o menores que un umbral.
Buscar archivos de más de 1 GB en el directorio home:
find ~ -type f -size +1G
Unidades comunes:
k: kilobytes
M: megabytes
G: gigabytes
Ejemplos:
find . -type f -size +100M
find . -type f -size -10k
4. Buscar archivos por fecha de modificación
Usa -mtime para días y -mmin para minutos.
Buscar archivos modificados en los últimos 10 minutos:
find . -type f -mmin -10
Buscar archivos modificados hace más de 30 días:
find /var/log -type f -mtime +30
Significado:
-10: less than 10 units ago
+30: more than 30 units ago
30: exactly 30 units, according to find's time rounding rules
5. Ejecutar comandos sobre los resultados
Usa -exec para ejecutar otro comando sobre los archivos coincidentes.
Buscar archivos .bak y eliminarlos en lote:
find . -type f -name "*.bak" -exec rm {} +
Cómo funciona:
{}se reemplaza por las rutas de archivos coincidentes.+agrupa muchos archivos coincidentes en un solo comando cuando es posible.\;ejecuta el comando una vez por archivo.
Prefiere esta forma por eficiencia:
find . -type f -name "*.bak" -exec rm {} +
Esta forma es más lenta con conjuntos grandes de resultados:
find . -type f -name "*.bak" -exec rm {} \;
Al eliminar archivos, previsualiza primero las coincidencias:
find . -type f -name "*.bak" -print
Después ejecuta el comando destructivo solo cuando hayas confirmado el conjunto de resultados.
6. Omitir directorios con prune
En proyectos de desarrollo, find puede perder tiempo escaneando directorios grandes como node_modules o .git. Usa -prune para omitirlos.
Buscar archivos JavaScript mientras se omite node_modules:
find . -path "./node_modules" -prune -o -name "*.js" -print
La lógica es:
If the path is ./node_modules, skip it.
Otherwise, find files matching *.js and print them.
Omitir tanto node_modules como .git:
find . \( -path "./node_modules" -o -path "./.git" \) -prune -o -type f -name "*.js" -print
Ejemplos prácticos
Buscar todos los archivos Markdown:
find . -type f -name "*.md"
Buscar todos los archivos modificados hoy:
find . -type f -mtime -1
Buscar directorios vacíos:
find . -type d -empty
Buscar archivos mayores de 500 MB:
find . -type f -size +500M
Buscar y renombrar archivos coincidentes con otro comando:
find . -type f -name "*.jpeg" -exec sh -c 'mv "$1" "${1%.jpeg}.jpg"' _ {} \;
Resumen
La clave para usar bien find es pensar en tres partes:
find [where] [match conditions] [action]
Usa -type, -name, -iname, -size y filtros de tiempo para acotar el resultado. Usa -exec para automatizar, pero previsualiza las coincidencias destructivas con -print antes de eliminar o modificar archivos.