find command is used to find files that match the criteria of the command-line arguments.
Syntax: find / -option file_name
Ex. find / name ssh.conf
Here, find is a command to fine file, / is a location where to search file, name is a option type and ssh.conf is a name of file for search.
Syntax: find / -option file_name
Ex. find / name ssh.conf
Here, find is a command to fine file, / is a location where to search file, name is a option type and ssh.conf is a name of file for search.
Search Files by ID
uid Search for files owned by user ID 1000
Ex. find -uid 1000
gid Search for files owned by group ID 2000
Ex. find -gid 2000
Search Files by permission
-perm option is used to Search files by file permission.
Ex. find /home -perm 764
Above command would match any file for which the user has read,write and execute permission and the group has read and write permission and others have read-only permission.
Above command would match any file for which the user has read,write and execute permission and the group has read and write permission and others have read-only permission.
Search files by size
Find files that match a size specified with the -size option,
- k, for kilobytes
- M. for megabytes
- G, for gigabytes
find -size 10M
Ex. Search files by size more than 10 gigabytes
find -size +10G
How to Find Files by Time
The -mmin option, followed by time in minutes, searches for all files taht had their content changed at exact the given time in the past.
Ex. Find files that had changed their content exactly 120 minutes ago.
find / -mmin 120
Ex. Find files that had changed their content more that 120 minutes ago.
find / -mmin +120
Ex. Find files that had changed their content less that 120 minutes ago.
find / -mmin -120
How to Find Files by Type of file
The -type option is set to search scope to a given file type.
- f, for regular file
- d, for directory
- l, for soft link
- b, for block device
find /etc -type d