In this follow-up, we are going to discuss the most useful examples of the find command which are commonly used by the Linux community to find in Linux.
The most useful examples of the find command in Linux
The find command is used to find the files from the directories and subdirectories of Linux, the general syntax of the find command is:
The find command is used with the options which specify the command to perform some particular tasks, then we have to define the path from where we want to find the files, and finally, we have to replace the expression with the file name which we want to find out.
Example 1 : Finding the file by its name
To search files by name we can use the option “name”, for understanding, we will find out file myfile.txt in the home directory using the command:
Example 2 : Finding the file excluding the case sensitivity
If we have doubts about the case sensitivity of the name of a file name, we can replace the option “name” with “iname”:
Example 3 : Finding the file through the extensions
The other way to find files is through their extensions, for example, we can find out the files of “.png” extensions by executing the command:
The above output displayed all the files in Linux with the extension of .png.
Example 4 : Using “type” option with find command
Similarly, there are different other options that can be used with the find command like the “type” option. It is used for different purposes, for example, to display all the directories we will use the “d” option:
In the executed command, we used the “.” which helps the find command to browse through the current directory.
Example 5 : Finding files using their size
We can find out the files by specifying their sizes:
Example 6 : Finding files using the date
The other useful example of find is to find files by using their modification date like we want to find out the “.txt” files that are modified in the last 30 days, we use the command:
Example 7 : Finding read-only files
To find out the read-only files use the command:
Likewise, to find the executable files, replace the “r” with “x” in the above command:
Example 8 : Finding files with multiple extensions
We can also find multiple files of different extensions using a single command, for example, we find the files having extensions “.txt” and “.png” using the command:
Example 9 : Finding the hidden files
We can also find out all the hidden files of the directory using the find command:
Example 10 : Finding the empty files
We can find out all the files and directories which are empty using the find command:
In the above command, we used the “f” flag that displayed the empty files, if we want to display the empty directories, use the “-d” flag.
Conclusion
The find command makes it convenient for us to save time and find the particular files instantly wherever it is in Linux, moreover, if we only know the extension name or its size, we can still find it using the find command. In this follow-up, we have discussed the most important usages of find command with examples in Linux. We use the find command to find out the files using the name, extensions, size, read-only, and execute-only files.