About Find Command

You may already know about Linux’s find command. In this tutorial we can learn how to use find command with some provided examples.

Finding by Name

This style of searching is sensitive. That means if you are searching for “cat” then you won’t be able to get results for “Cat”.

find  -name “query”

This searching is an insensitive, that means if you are searching for “cat” then you will be able to get

find   -iname “query”

If the keyword does not follow a specific pattern, you can invert the search with “-not” or “!”. While using the “!”, you should escape the character in order to interpret before the execution of the find command.

find  -not  -name “query_to_avoid”

or

find \! -name “query_to_avoid”

 

Finding by Type

Here you can set the type of file you are searching for with the “-type” parameter. The syntax is:

find  -type type_descriptor query

The most commonly used descriptor to specify the type of file are:

1) f: regular file

2) d: directory

3) l: symbolic link

4) c: character devices

5) b: block devices

 

Filtering by Time and Size

This filtering system helps to filter out by size and time.

 Size

“size” parameter is used to filter by size.

Suffix values are specified

These are some popular options:

c: bytes

k: Kilobytes

M: Megabytes

G: Gigabytes

b: 512-byte blocks

 

Time

The access times, modification times, and change times are stored in Linux.

1) Access Time: Last time a file was read or written to.

2) Modification Time: Last time the contents of the file were modified.

3) Change Time: Last time the file’s inode meta-data was changed.

These are the corresponding parameters “-atime”, “-mtime” to be used. In addition, with that we can use plus and minus symbols to specify the greater or less than the time specified.

We can also find the details with reference to the days specified

To find files that have a modification time of 3 days ago, type:

find / -mtime 3

To get files that last had their meta information changed more than 4 days ago, type:

find / -ctime +4

 

Finding by Owner and Permissions

We also have the feature to search the files with owner or group owner.

We do this by using the “-user” and “-group” parameters respectively.  To find a file which has the ownership “user1” user can be found by:

find / -user user1

To find a file which has the group ownership “redhat” user can be found by:

find / -group redhat

We can also search for files with specific permissions.

To get the files matching the file permissions:

find / -perm 644

This will match files with exactly the permissions specified.

In order to match any of the mentioned permissions:

find / -perm -644

 

This will match any files that have additional permissions. A file with permissions of “744” would be matched in this instance.

 

If you need any further assistance please contact our support department.

Was this answer helpful? 0 Users Found This Useful (0 Votes)