
© Profit_Image / Shutterstock.com
You’ll use the “find” command most frequently when working with Linux or any other Unix-like operating system. It’s self-explanatory in what it does; it simply finds things. But little do you know this basic command can find what you need in multiple ways.
The find command can search for a file based on filename, permissions, users, type, size, and date, among other criteria. Knowing how to use the find command in Linux with different conditions can help you retrieve files quickly. Some commands are more advanced, so you probably won’t use them that frequently. If you’re a beginner, you can work your way up by first understanding the simpler examples of the find command.
Find Command in Linux Syntax
Here’s the general syntax of the find command in Linux:
$ find [where to begin the search] [-options] [what to find]
In the above syntax, [-options] is the criterion for the search, which essentially defines the command and tells the operating system what to do.
Here are some of the -options you’ll use:
- -exec CMD
- -ok CMD
- -inum N
- -links N
- -name demo
- -newer file
- -perm octal
- -empty
- -size +N/-N
- -user name
How to Use Find Command in Linux Examples
So there are tens of different ways you can use the find command in Linux to search for a file. You can also use the same find command not just to locate the file but also to carry out other actions to, for example, delete the file.
To help you better understand how this type of command works in Linux, here are several examples, from basic to advanced.
Example 1: Search for a File With Its Name
This command is straightforward as it searches for the file using its name in your defined directory. If you know the name of the file and its directory, you can use this command to pull it out easily.

©History-Computer.com
This command will look for files named “sample.txt” in the home directory.
Example 2: Search for All Files With the Same Extension
Suppose you don’t remember the name of the file, but you do remember the type. You can retrieve all files with a specific extension or type using this command.

©History-Computer.com
This will return all .txt file types in the home directory.
Example 3: Search for a File With the Name in the Current Directory
If the file you’re looking for is in the current directory, you don’t need to mention the directory in the command. Here’s how it goes:

©History-Computer.com
This will search for the file titled “sample.txt” in the current directory.
Example 4: Search for a Directory
You can also use the find command in Linux to search for directories. Here’s an example of a find command to search for a directory named HC.

©History-Computer.com
This command will take you to the directory named HC.
Example 5: Search for a File With Its Name, But Without Case Sensitivity
Linux commands are case-sensitive, so you have to be careful with the file and directory names. But there’s a workaround find command for finding files based on name, regardless of their case. Again, this can be helpful if you’re unsure about the case of the filename.

©History-Computer.com
This command will return “sample.txt”, even if its actual name is “Sample.txt”.
Example 6: Search by Type
In instances where you may have a directory and file having the same name, you can make your search accurate by specifying the type of object you’re looking for. For instance, you can specify that you’re searching for a file with the -type option.

©History-Computer.com
This command will return only files titled “sample”, which are text files.
Example 7: Search for Text in Files
Suppose you want the contents of the file, like a string in a text file. You can use find to retrieve the text directly. The find command can also be tweaked to search for text within one or multiple files. You’ll need to provide the string you’re looking for.

©History-Computer.com
This command will print text lines with the string “History-Computer” in all .txt files in all the directories.
Example 8: Search for All Empty Files
If you’re looking to clean your directory, you’ll want to delete any empty files. But how do you know which files are empty? You can use the find command to look for empty files.

©History-Computer.com
This command will return all the empty files in the home directory.
Example 9: Search for All Empty Directories
Like empty files, you can also use the find command in Linux to search for empty directories.

©History-Computer.com
This command will return all the empty directories or sub-directories.
Example 10: Search for All Hidden Files
The find command is also useful for finding hidden files in a directory. The command is pretty straightforward.

©History-Computer.com
This command returns all the hidden files in the home directory.
Example 11: Search for Files With Particular Permissions
When working with Linux operating system with multiple users, you may want to ensure your files have the right permissions, so not everyone can access them. You can use the find command to filter the search by the given permissions. For instance, you want to find files in the current directory whose permissions are 664. Here’s how you’ll do that:

©History-Computer.com
This command will return all the files in the home directory with permission set to 664.
Example 12: Search for Files Without Particular Permissions
Just as you can use the find command to find a file with specific permissions, you can also find files without permissions. Here’s an example for finding files whose permissions are not 664:

©History-Computer.com
This shall return only files whose permissions do not include 664.
Example 13: Search for All SUID Files
Set Owner User ID is a permission bit for executable files in Linux. An alternate user can run this file with the same permissions as the owner. Here’s how you can find all the SUID files.

©History-Computer.com
This command returns all the SUID files.
Example 14: Search for All SGID Files
SGID is similar to SUID but for groups. Here’s how you can search for all SGID files.

©History-Computer.com
This command returns all the SGID files.
Example 15: Search for All Executable Files
Looking for an executable file but don’t know the name? You can also use the -perm option to search for all the executable files in current or all directories.

©History-Computer.com
This command will return executable files in the home directory.
Example 16: Search for Read-Only Files
You can use the find command if you want read-only files in the current directory or any directory. This can be helpful to ensure that certain important files have read-only permission. Here’s how you do it for all the directories.

©History-Computer.com
This will return read-only files in the home directory. Of course, you can also specify the directory and/or file type.
Example 17: Search and Delete a File
If you want to delete a file, you can do it with the find command. Here’s one example of such a command:

©History-Computer.com
Example 18: Search and Delete Multiple Files
You can also delete two or more files using a find command with some tweaks. Here’s what it should look like.

©History-Computer.com
This command will delete all .txt files in the home directory. You can also specify another directory or go with all directories.
Example 19: Search for a File Based on User
The option “-user” allows you to search files for a specific user on the operating system. This can be used to further narrow the search and ensure only the right file returns. If you want to find a single file for a specific user, here’s an example of a command:

©History-Computer.com
This find command in Linux will return the specific file for this particular user.
Example 20: Search for All Files for a User
Perhaps you want to check which files belong to a certain user. You can search for all files for a specific user using a similar find command.

©History-Computer.com
In the above command, “historycom” is the username. This will return all the files for this specific user.
Example 21: Search for Specific Files for a User
You can use the find command to search only for a specific type of user files. Here’s an example:

©History-Computer.com
This command will return all .txt files for the user historycom.
Example 22: Search for All Files for a Group
As Linux also has groups, files can be shared. One way to check which files belong to a particular group, is to search for files for a single group. Here’s what that would look like:

©History-Computer.com
In the above command, “historycom” is the group’s name. This command will return all the files for this particular group.
Example 23: Search for All Files Changed or Modified in the Last Hour
If, for any reason, you want to check which files were modified or changed in the last hour (for example, in the case of an attack), you can use the find command in Linux to search for recently changed or modified files quickly. The commands for changed and modified files are different.
Here’s an example of a command to find all files changed in the last hour:

©History-Computer.com
Here’s an example of a command to find all files modified in the last hour:

©History-Computer.com
Example 24: Search for All the Files Accessed in the Last Hour
Another commonly used find command is searching for files accessed in a particular time frame. Here’s how you can find all the files accessed in the last hour:

©History-Computer.com
This will give you all the files accessed in the last 60 minutes. You can specify a directory as well.
Example 25: Search for All Files Accessed in the Last 10 Days
Like the above command, you can also search by the number of days for files accessed. Here’s what such a command will look like:

©History-Computer.com
This will return all the files accessed in the last 10 days.
Example 26: Search for All Files Modified or Changed in the Last 10 Days
If you changed or modified a file in the recent past and forgot which one it was, there’s a simple find command to locate such a file. The find commands for finding modified and changed files in the past are similar. Here’s the command for modified files:

©History-Computer.com
Here’s the command for changed files:

©History-Computer.com
Example 27: Search for All Files Accessed in a Timeframe
If you want to search for files accessed in a particular time frame, for example, within the last 20 to 10 days, you can specify the duration of the find command. Here’s an example:

©History-Computer.com
This will return all the files accessed more than 10 days back but less than 20 days back.
Example 28: Search for Files by Size
Suppose you’re making space in a directory and want to delete any large files. You can also search for files by size. For instance, you want all files sized 100MB; here’s the command you’ll use:

©History-Computer.com
This will return all the files sized 100MB from all the directories.
Example 29: Search for Files by Size Range
Similar to a specific file size, you can use the find command with a size range.

©History-Computer.com
This command will return all files ranging from 50MB to 100MB.
Example 30: Search and Delete Files of a Particular Size
You can find and delete all files of a specific size. Here’s an example of such a command:

©History-Computer.com
This will delete all .txt files of 50MB size from all directories. Be careful with this command because you don’t want to delete any file you didn’t aim to delete. So it’s best to specify the name of the file with this command.
Wrap Up
Now you know many ways to use the find command in Linux to search for files or folders. But that’s not all; you can also do other things like specify the kind of files you need. Most of the commands are straightforward, and you might use them daily.
While the primary job of the find command is to search for files, you can also include other prompts in the same command, such as deleting files. Ensure you define the path carefully when deleting files using the find command, so you don’t accidentally delete other files.