Updated April 15, 2023
Introduction to Linux Find Command
In the Linux operating system, the find command is a very common and highly usable command. The find command is used to locate or search the files or directories on the Linux environment. The searching of the files and directories is based on the specific criteria, or in other words, it will depend on the compatible options. While working with the find command, we can use different conditions to search like users, dates, groups, permissions, size, file type, etc. Furthermore, we can use the find command with multiple commands or operators. In other words, we can also say that the find command is for recursively filtering the objects in the Linux file system. The filtering is based on an input option or condition.
Syntax of Text Editors
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
- find: We can use the “find” keyword in the syntax or command. It will take different arguments like OPTION, expression, the path of the files or directories, etc. The provided arguments will find the required files or directories on the Linux operating system.
- The find command options like -H, -L, and -P will control the treatment of symbolic links. The Command-line arguments will help to take the names of files or directories to be examined up to the first argument that begins with “-”.
- PATH: We can provide a different file or directory path to the find command.
- expression: As per the requirement, we can use the custom expression or system expression with the find command.
How does Linux Find Command work?
In the Linux environment, we are having multiple tools for searching and locating the files or directories. But the find command-line utility is handy and quick. We can use the multiple combinations of custom expressions for searching the files or directories. The find command will accept different arguments like options, expression, file or directory path, etc. As per the input arguments, the find command will search or locate the files or directories in the Linux operating system.
Below is the list of option we can use with the find command.
Sr No | Option | Description |
1 | -gid n | The file’s numeric group ID is n. |
2 | – group gname | The file belongs to the input group gname. But the numeric group ID allowed. |
3 | -ilname pattern | It will accept Like -lname, but the match is case insensitive. |
4 | -iname pattern | The options like -name but the match is case insensitive. |
5 | -inum n | The file has an inode number that is n. Therefore, it is easier to use the -samefile test instead. |
6 | -ipath pattern | The file-like -path, but the match is case insensitive. |
7 | -iregex pattern | It is a -regex, but the match is case insensitive. |
8 | -iwholename pattern | It will see the -ipath. The alternative is less portable than -ipath. |
9 | -links n | The files have an “n” number of links. |
10 | -lname pattern | The files are symbolic links whose contents match shell patterns. |
11 | -mmin n | It will help to identify the last modified data in “n” minutes ago. |
12 | -mtime n | It will help to identify the last modified data in “n*24 hours” minutes ago. |
Examples to implement Linux Find Command
Given below are the examples of Linux Find Command:
Example #1 – Find File in “/” Directory
The find command is very simple and easy to use. We are searching for the required files in the “/” location.
Command :
find / -name elearning
Explanation :
We are finding the “elearning” files in the “/” location.
Output :
Example #2 – Find File in Working Directory
In Linux, we are able to find the files in the current or working directory.
Command :
find /home/user1 -name elearning
Explanation :
As per the above command, we are finding the “elearning” files in the “/home/user1” location.
Output :
Example #3 – Ignore Case
By default, the find command is case sensitive. To overcome this condition, we need to use the “-i” option.
Command :
find / -iname eleaRnInG
Explanation :
We are finding the case insensitive file (“eleaRnInG”) on the “/” location.
Output :
Example #4 – Find the Directory
In Linux, we are able to search the files. Similarly, we are able to search the directories also. Therefore, we need to use the “-d” option with the find command.
Command :
find / -type d -name dir_elearning
Explanation :
As per the above command, we are finding the “dir_elearning” directory on the “/” location.
Output :
Example #5 – With File Extension
In the find command, we have the functionality to find the file with a specific file extension.
Command :
find / -type f -name "*.zip"
Explanation :
We are finding all the “zip” files on the “/” location.
Output :
Example #6 – Find File with Permission
In the Linux find command, we are able to find the files as per the file permission.
Command :
find /home -type f -perm 0644 -print
Explanation :
As per the above command, we are finding the files that are having the rw, r, r, permission on the “/home” location.
Output :
Example #7 – Find Executable File
In the find command, we are able to find the files that are having the executable permission.
Command :
find /home -perm /a=x
Explanation :
As per the above command, we are finding only the executable files on the “/home” location.
Output :
Example #8 – Find Empty File
In the Linux find command, we are able to find the empty file.
Command :
find /home -type f -empty
Explanation :
As per the above find command, we are finding the “empty” file on the “/home” location.
Output :
Example #9 – Find Hidden Files
In the find command, we are able to find the hidden files
Command :
find /home/user1 -type f -name ".*"
Explanation :
As per the above command, we are finding the hidden files on the “/home/user1” location.
Output :
Conclusion
We have seen the uncut concept of “Linux Find Command” with the proper example, explanation, and command with different outputs. Then, as per the requirement, we are able to find the files or directors with multiple conditions.
Recommended Articles
We hope that this EDUCBA information on “Linux Find Command” was beneficial to you. You can view EDUCBA’s recommended articles for more information.