# Procurando Arquivos

### Find

Procurando um arquivo chamado `file.txt` no diretório `/etc`

```bash
find <directory> -name <file_name>
```

Procurando por arquivos e executando um comando. No exemplo abaixo estamos filtrando por todos todos os arquivos com determinado nome, em determinado local e que contenha uma determinada string.&#x20;

```bash
find <directory> -name <file_name> -exec grep <find_string> {} \;
find <directory> -name <file_name> -exec cat {} \; | grep <find_string>
```

{% hint style="info" %}
O comando acima foi feito com o intuito de aprendizado do comando **`find`**, pois na prática, isso poderia ser facilmente substituído por: **`grep -irn <find_string>`**
{% endhint %}

Também podemos simplesmente digitar o comando `find` ou `find <dir>` para mostrar todos os arquivos de forma recursiva, semelhante ao comando `ls -lRha`, porém sem os detalhes dos arquivos.

### Locate

Procurando arquivos

```bash
locate nome_arquivo
locate *.php
```

{% hint style="info" %}
**NOTA:** O comando **`locate`** é mais rápido que o comando **`find`**, pois o Linux indexa todos os arquivos em um tipo de base de dados próprio. Caso tenha acabado de criar um arquivo, pode ser que o comando locate não o encontre, mas podemos contornar isso forçando uma atualização desse banco de dados com o comando **`updatedb`**
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mysther.gitbook.io/knowledge-base/sistemas-operacionais/linux/utilizacao/trabalhando-com-arquivos/procurando-arquivos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
