Finding files with find · Encontrando arquivos com 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.
Buscando toda a árvore
lsmostra uma pasta.findpesquisa uma pasta e tudo dentro dela, independentemente da profundidade:
find .
.significa "começar na pasta atual".findlista todos os arquivos e pastas que ela pode alcançar.
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.
Encontrar por nome
- Geralmente você quer arquivos correspondendo a um padrão. Use
-name:
find . -name "*.txt"
- Isso encontra todos os arquivos
.txtna árvore — até aqueles enterrados três pastas abaixo. - Aspas no padrão (
"*.txt") para que o shell o passe parafindintacto.
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 que é prático
- "Onde coloquei aquele arquivo?" —
findresponde em uma linha. - Combinado com pipes, você pode agir sobre os resultados — por exemplo, contá-los com
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.
Erros comuns
find . -name "*.txt"busca por nome da pasta atual para baixo.- Aspas no padrão para que o shell não o expanda primeiro.
find walks the tree · find percorre a árvore
find searches the whole tree below a directory. · find busca toda a árvore abaixo de um diretório.
Find every .txt file, even deep inside subfolders, with find . -name "*.txt". (. means "start from here".) · Encontre todos os arquivos .txt, mesmo dentro de subpastas profundas, com find . -name "*.txt". (. significa "começar daqui".)
You can also start the search from a subfolder. Find just the .txt files inside docs (and below) with find docs -name "*.txt". · Você também pode começar a busca de uma subpasta. Encontre apenas os arquivos .txt dentro de docs (e abaixo) com find docs -name "*.txt".