Last Sync: 2022-05-25 08:00:04

This commit is contained in:
tactonbishop 2022-05-25 08:00:04 +01:00
parent 15f260e152
commit 807e851a0d

View file

@ -0,0 +1,59 @@
---
tags:
- Programming_Languages
- shell
---
# `find`
`find` can be used both to locate files and run operations on the files it finds.
## Main syntax
### No options
Without options specified, `find` alone will return a recursive index of all the files in the directory from which it is run.
### Sub-directory
If we pass a directory to `find` it will repeat the above process but specifically for that directory.
```bash
$ find i3
i3
i3/config
```
### Filters
We can specify flags as filters (known as 'tests' within the program).
#### Type
Filter by type: file or directory
```
$ find -type d # return dirs only
$ find -type f # return files only
```
Within a specified directory:
```bash
$ find i3 -type f
```
### Filename
This is the most frequent use case: filter files by name with globbing.
```bash
$ find -name "config"
./.git/config
./i3/config
```
```bash
$ find -name "*.js"
```
The same, but case insensitive: `iname`
```bash
$ find -iname "*.JS"
```