2.3 KiB
		
	
	
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			2.3 KiB
		
	
	
	
	
		
			Executable File
		
	
	
	
	
The find command
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.
Examples:
- 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
Syntax:
find [options] [paths] [expression]
In Simple words
find [where to start searching from]
 [expression determines what to find] [-options] [what to find]
Additional Flags and their Functionalities:
Commonly-used primaries include:
- namepattern - tests whether the file name matches the shell-glob pattern given.
- typetype - 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. | 
Help Command
Run below command to view the complete guide to find command or click here.
man find