Finding files with find · Encontrar archivos con find
Searching the whole tree
lsshows one folder.findsearches a folder and everything inside it, however deep:
.means "start in the current folder".findlists every file and folder it can reach.
Buscar en todo el árbol
lsmuestra una carpeta.findbusca en una carpeta y en todo lo que hay dentro, sin importar la profundidad:
find .
.significa "empezar en la carpeta actual".findenumera todos los archivos y carpetas a los que puede acceder.
Find by name
- Usually you want files matching a pattern. Use
-name:
- This finds every
.txtfile in the tree — even ones buried three folders down. - Quote the pattern (
"*.txt") so the shell passes it tofinduntouched.
Búsqueda por nombre
- Por lo general, quieres buscar archivos que coincidan con un patrón. Usa
-name:
find . -name "*.txt"
- Esto encuentra todos los archivos
.txten el árbol, incluso aquellos enterrados tres niveles de carpetas hacia abajo. - Encierra el patrón entre comillas (
"*.txt") para que la terminal se lo pase afindtal cual.
Why it is handy
- "Where did I put that file?" —
findanswers it in one line. - Combined with pipes, you can act on the results — for example count them with
wc -l.
Por qué es útil
- "¿Dónde dejé ese archivo?" —
findresponde en una sola línea. - Combinado con tuberías (pipes), puedes actuar sobre los resultados; por ejemplo, contarlos con
wc -l.
Common mistakes
find . -name "*.txt"searches by name from the current folder down.- Quote the pattern so the shell does not expand it first.
Errores comunes
find . -name "*.txt"busca por nombre desde la carpeta actual hacia abajo.- Encierra el patrón entre comillas para que la terminal no lo expanda primero.
find walks the tree · find recorre el árbol
find searches the whole tree below a directory. · find busca en todo el árbol debajo de un directorio.
Find every .txt file, even deep inside subfolders, with find . -name "*.txt". (. means "start from here".) · Encuentra todos los archivos .txt, incluso dentro de subcarpetas profundas, con find . -name "*.txt". (. significa "comenzar desde aquí".)
You can also start the search from a subfolder. Find just the .txt files inside docs (and below) with find docs -name "*.txt". · También puedes comenzar la búsqueda desde una subcarpeta. Encuentra solo los archivos .txt dentro de docs (y sus subdirectorios) con find docs -name "*.txt".