The find command with its name defines its usage that the find command is used in Linux to find out the files, directories, and the documents. The find command in the Linux can search the files and directories not only by their names but also using their extensions.
In this article, we will explore more about the usage of the find command which is a UNIX command-line utility.
What is the usage of the find command in Linux?
As explained above that the find command is a command-line utility which is used to find the files and directories in the Linux operating system. The general syntax of using the find command in Linux operating system is:
$ find [starting point of searching] [expression determines what to find] [-options] [file/directory to be searched]
The explanation of the above general syntax is as we will use the find command, then will specify the directory where it should start searching that particular file, next expression will define the parameter by which the file is to be searched, then different type of options can be used, and finally the file which has to be found should be write.
What are the different options that can be used with the Find command
There are different options which can be used with the find command to perform different tasks:
Options | Purpose |
empty | It will find for the empty files and directories |
It will display the path name of the files which are searched in the result | |
username | It will searched the files or directories by the names of the username |
name | It will search the files or directories by using their names |
perm | It is used to find the files having specific permissions allowed |
type | It is used to find specific type of results like “f” is used to find files only |
What are the examples of the usage of the find command
We will perform some examples in order to understand the usage of the find command, first we will find the file by its name, for example, we will search for the file name, myfile.txt using the command:
$ find -name myfile.txt
Now we will find afile in the Downloads directory by using the command:
$ find ./Downloads -empty myfile.txt
The above output showing that there is no file exist with the above name and size, now if we are confused about the case sensitivity of the file name, then we can use the “iname” option:
$ find ./Downloads -name Firefox.tmp
The name of the resulted file is in lower case, but it is still findable, similarly, if we want to find the files with the extension, for example we want to find out the files with the png extension, then we will use the command:
$ sudo find /home/user3 -name “*.png”
We can also find out the files by specifying their sizes, for example, we extract the files of siz 1M using the command:
$ find . -type f -size -1M
Conclusion
The find command makes it easy for the Linux users to find out the specific file in few seconds rather than to find it manually by visiting the every directory. In this write-up, we have explore the basic usage of the find command with the help of some examples and understanding its general syntax.
TUTORIALS ON LINUX, PROGRAMMING & TECHNOLOGY