Read in 7 minutes

last updated 

How to Find Files in Linux Using the Command Line

Find is a command-line utility which allows you to search for files and directories in a directory hierarchy based on a user given expression and applies a user-specified action on each matched file.

The Linux Find command is one of the most powerful tools in the Linux system administrators arsenal.

You can use the find command to search for files based on the file permissions, type, date, ownership, size and more. It also can be used in combination with other tools such as grep or sed to perform operations on those files.

Linux Find Command Syntax

Before going into how to use the find command, let’s start by reviewing the basic syntax.

The find utility expressions take the following form:

find [options] [path...] [expression]
  • The options attribute controls the treatment of the symbolic links, debugging options and optimization method.
  • The path... attribute defines the starting directory or directories where find will search the files.
  • The expression attribute is made up of options, search patterns and actions separated by operators.

Let’s take a look at the following example:

find  -L /home/projects/ -name "*.js" -exec chmod 644 {} \;

This command includes a parameter -L (options) which allows the find command to follow symbolic links, searches the entire directory tree beneath /home/projects/ (path…) for all files ending with .js (expression) and set the permissions of all matched files to 644.

Find Files by Type

To specify the type of the files you want to find use the -type parameter.

You can use the following descriptors to specify the file type:

  • f: a regular file
  • d: directory
  • l: symbolic link
  • c: character devices
  • b: block devices
  • p: named pipe (FIFO)
  • s: socket

For instance, if you want to find all directories in the current working directory you would use:

find . -type d

If you want to list all character devices on your system type:

find / -type c

To change all file permissions to 644 and all directory permissions to 755 recursively run the following command:

find /var/www/my_project -type d -exec chmod 0755 {} \;
find /var/www/my_project -type f -exec chmod 0644 {} \;

Find Files by Name

Finding files by name is probably the most common use for the find command. To find a file by its name pass the -name option along with the name of the file you are searching for.

To search for a file called document.pdf in the /home/linuxize directory you would use the following command:

sudo find /home/linuxize -type f -name document.pdf

If you want to run a case-insensitive search then change the -name option with -iname:

sudo find /home/linuxize -type f -iname document.pdf

The command above will match Document.pdf, DOCUMENT.pdf ..etc.

Find Files by Extension

Searching for files by extension is the same as searching for files by name. For example, if you want to find all files ending with .log.gz inside /var/log/nginx directory you can use:

find /var/log/nginx -type f -name '*.log.gz'

It is important to mention that when you use wildcard character you must either quote the pattern or escape the asterisk * symbol with backslash \ so that it doesn’t get interpreted by the shell.

If you want to find all files that don’t match the regex *.log.gz you can use the -not parameter. For example, to find all files that don’t end in *.log.gz you would use:

find /var/log/nginx -type f -not -name '*.log.gz'

Find Files by Size

To find files based on the file size, pass the -size parameter along with the size criteria. You can use the following suffixes to specify the file size:

  • b: 512-byte blocks (default)
  • c: bytes
  • w: two-byte words
  • k: Kilobytes
  • M: Megabytes
  • G: Gigabytes

For example, to find all files of exactly 1024 bytes inside the /tmp directory, you would run the following command:

find /tmp -type f -size 1024c

The find command also allows you to search for files that are greater or less than a specified size.

In the following example we are searching for all files less than 1MB inside the current working directory, notice the minus - symbol before the size value:

find . -type f -size -1M

If you want to search for files with size greater than 1MB, then you need to use the plus + symbol:

find . -type f -size +1M

You can even search for files within a size range. For example, the following command will find all files between 1 and 2 MB :

find . -type f -size +1M -size 21M

Find Files by Modification Date

The find command can also search for files based on the last modification, access or change time.

Same as when searching by size, you can use the plus and minus symbols to specify greater than or less than.

Let’s say that a few days ago, you modified a dovecot configuration file but you forgot the file name. You can easily filter all files in the /etc/dovecot/conf.d/ directory that ends with .conf and has been modified in the last 5 days with:

find /etc/dovecot/conf.d -name "*.conf" -mtime 5

Here is another example of filtering files based on the modification date using the -daystart option.

The command below will list all files in the /home directory that were modified 30 or more days ago:

find /home -mtime +30 -daystart

Find Files by Permissions

To filter files based on the file permissions, use the -perm option.

For example, to find all files with permissions of exactly 775 inside the /var/www/html directory you would use:

find /var/www/html -perm 644

You can prefix the numeric mode with minus - or slash /.

When slash / is used as the prefix, then at least one category (user, group or others) must have at least the respective bits set for a file to match.

Consider the following example command:

find . -perm /444

The above command will match all files with read permissions set for either user, group or others.

If minus - is used as the prefix then for the file to match at least the specified bits must be set.

The following command will search for files that have read and write permission for the owner and group and are readable by other users:

find . -perm -664

Find Files by Owner

To find files owned by a particular user or group you can use the -user and -group options.

For example, to search for all files and directories owned by the user linuxize, you would run:

find / -user linuxize

Here is more advanced example, let’s say you want to find all files owned by the user www-data and change the ownership of the matched files from www-data to nginx:

find / -user www-data -type f  -exec chown nginx {} \;

Find and Delete Files

To delete all matching files add the parameter -delete to the end of the match expression.

Make sure you are using this option only when you are certain that the result matches the files that you want to delete. It is always a good idea to print the matched files before using the -delete option.

For example to delete all files ending with .temp from the /var/log/ you would use:

find /var/log/ -name `*.temp` -delete
Use the -delete option with extreme caution. The find command line is evaluated as an expression and if you add the -delete option first, the command will delete everything below the starting points you specified.


In this tutorial, you have learned how to use the Linux find utility based on various criteria and now you should have a fundamental understanding of how to locate files on your Linux systems.

You may also visit the find man page and read about all other powerful options of the Find command.

If you have any question or remark, please leave a comment below.