“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

1
2> Find all the files with ‘.conf’ filename extension inside the /etc directory

2
3> Find all the empty files (0 length files) inside the current directory

3
4> Find all the files and directories inside the whole system that have the permission ‘770‘ and t hat belongs to the user ‘test’

4
5> Find all the directories inside the /var/log directory

5
6> Find all the files in /etc that have length
a) Exactly 100KB

6
b) Within 100KB

7
c) Greater than 100KB

8
d) That have 100 characters in it.

9

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

10
8> Find all the configuration files with .conf filename extension inside the /etc directory and copy them into the /home/test/backup directory

11
9> Find all the readonly files
12
10>Find all the directories with 770 permission and chmod to 755
14
11> Find all empty directories
15
12> Find all the empty file in current directly only and delete each one showing a prompt
16
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
17

Advertisements