The find
command lets you search for files in a directory hierarchy
- Search a file with specific name.
- Search a file with pattern
- Search for empty files and directories.
- Search a file with specific name:
find ./directory1 -name sample.txt
- Search a file with pattern:
find ./directory1 -name '*.txt'
- To find all directories whose name is test in / directory.
find / -type d -name test
- Searching empty files in current directory
find . -size 0k
find [options] [paths] [expression]
In Simple words
find [where to start searching from]
[expression determines what to find] [-options] [what to find]
Commonly-used primaries include:
name
pattern - tests whether the file name matches the shell-glob pattern given.type
type - tests whether the file is a given type. Unix file types accepted include:
options | Description |
---|---|
b |
block device (buffered) |
d |
directory |
f |
regular file |
l |
Symbolic link |
-print |
always returns true; prints the name of the current file plus a newline to the stdout. |
-mtime n |
find's all the files which are modified n days back. |
-atime n |
find's all the files which are accessed 50 days back. |
-cmin n |
find's all the files which are modified in the last 1 hour. |
-newer file |
find's file was modified more recently than file. |
-size n |
File uses n units of space, rounding up. |
Run below command to view the complete guide to find
command or click here.
man find