“Find” command searches all the files and directories inside directory that matches the given criteria like name, size, ownership, permission etc.
syntax:
find <path> [option/criteria] <argument>
option can be:
-atime <+N/-N/N> :- Access time based search
-mtime <+N/-N/N> :- Modification time based search
-name <Name> :- Name based search
-size <+N/-N/N> :- Size based search
-user <owner> :- owner based seach
-group <group> :- Group based search
-perm <permission> :- Permission based search
-type <type> :- File type based search
type can be ‘f’ or ‘d’ denoting searches for files only or directory only respectively
Examples;
1> Find all the files inside /home/test directory that have been modified within 7 days
2> Find all the files with ‘.conf’ filename extension inside the /etc directory
3> Find all the empty files (0 length files) inside the current directory
4> Find all the files and directories inside the whole system that have the permission ‘770‘ and t hat belongs to the user ‘test’
5> Find all the directories inside the /var/log directory
6> Find all the files in /etc that have length
a) Exactly 100KB
d) That have 100 characters in it.
Furthermore, three logical characters can be used to create more filtered search expression for the find query command.
-and
-o
!
7> Find all the empty files inside the current directory and remove them all
8> Find all the configuration files with .conf filename extension inside the /etc directory and copy them into the /home/test/backup directory
9> Find all the readonly files
10>Find all the directories with 770 permission and chmod to 755
11> Find all empty directories
12> Find all the empty file in current directly only and delete each one showing a prompt
13> Find all the files or folder in current directory and copy all the files to /backup directory preserving the permissions, times and ownership of every file and subdirectory