← linux commands
Views:
find command
The find command is used to search for files or folders.
Syntax: find path [options] expression
Example:
find . -name 'Button.js'

Options:
-name
To specify the name you're searching for.
Example
Same as above
-type
To specify the type of file/folder you're searching.
The most popular values for this flag are: d and f which stand for directory and file respectively.
Example:
find . -type d -name 'assets'

-regex
To search for files/folders which matches given regex pattern.
Example:
Suppose we have to find all .style.js files in current codebase, we can give regex for that as follows:
find . -regex '.*/*.style.js'

-size
To search for files/folders with specific size or size range.
Size Units
- b - for 512-byte blocks (default)
- c - for bytes
- w - for two-byte words
- k - for Kilobytes
- M - for Megabytes
- G - for Gigabytes
Size Constraints
- For specific size: -size 100M
- For greater than 100MB: -size +100M
- For lesser than 100MB: -size -100M
- Between 100MB and 200MB: -size +100M -size -200M
Example:
Suppose we have to find image files (jpeg/png) which are greater than 100 kilobytes, we can do that by using size flag as follows:
find -E . -type f -regex '.*\.(jpeg|png)' -size +100k
Note: Here -E flag allows to interpret modern regex syntax.

-and/-a, -or/-o, -not
Logical operators for combining your expressions
Example:
# NOT Operator
find . -type f -not -name '*.js'
# AND Operator
find . -name '*.png' -and -size +100kb
# OR Operator
find . -name 'SearchInput.js' -or -name 'Button.js'
