Search for files using find

The find command is used in Linux to search for files in the directory tree starting from the location specified. It searches your filesystem live, which causes the command to run slower than the locate command.

The syntax of the command is:

find PATH EXPRESSION

The expression is a way of specifying what you want to find. You can search files by filename, size, permissions, group, UID, etc.

Here is a list of the most commonly used expressions:

linux find command options

We will go through a couple of examples. To find all files and directory that begin with so in our current directory, we can use the following command

linux find by filename

Wildcards like * have to be enclosed in double quotes to work with the find command.

 

To find files bigger then 300 bytes, use the following command:

linux find by size

When using the -size expression, use c for bytes, k for Kilobytes, M for Megabytes and G for Gigabytes.

 

To find files owned by a particular user:

linux find by ownerr

To find files with specific permissions:

linux find by permissions

You can also combine two or more expressions:

linux find command multiple expressions

In the example above we have found all files that have the permissions of 775 and begin with the letter t.

Geek University 2022