Linux Find Command

The find command in Linux is used to search for files and directories in a directory hierarchy. It is a powerful tool with many options to customize the search.

Options and Examples

Option Description Example
-name Search for files by name. find /path/to/search -name "file.txt"
-type Search for a specific type of file (e.g., f for files, d for directories). find /path/to/search -type d
-size Search for files by size (e.g., +1M for files larger than 1MB). find /path/to/search -size +1M
-mtime Search for files modified within the last N days. find /path/to/search -mtime -7
-exec Execute a command on the found files. find /path/to/search -name "*.log" -exec rm {} \;
-user Search for files owned by a specific user. find /path/to/search -user username
-iname Search for files by name, ignoring case. find /path/to/search -iname "*.jpg"
-inum Search for files by inode number. find /path/to/search -inum 123456
-empty Search for empty files or directories. find /path/to/search -empty
-perm Search for files with specific permissions. find /path/to/search -perm 644
-group Search for files owned by a specific group. find /path/to/search -group groupname

Basic Example

To find all files with the extension .txt in the /home directory:

find /home -name "*.txt"

Advanced Example

To find all files larger than 10MB and delete them:

find /path/to/search -size +10M -exec rm {} \;