Linux being an open-source platform, offers a much more comprehensive and secure network as compared to Windows. The open-source feature provides easy accessibility, eliminates the platform’s vulnerabilities, and creates solutions that enable faster processing and saves time.
Linux supports all the major programming languages, which is why programmers use it on a large scale. Linux offers native support that caters to the needs of managing servers with ease. With room for customisation, it opens up a world of possibilities and provides an enhanced user experience.
It also offers better community support. One can easily connect with others to solve a persisting problem at no cost. There are many active Linux users worldwide, and these users are responsive to finding solutions that help the community. This helps to avoid looking for resources and doing rigorous research.
It takes time to get used to the Linux interface and its features as it is a customised platform. Looking for a file source from the terminal on a Linux system can be challenging in the initial days. There are different command lines and techniques for locating files. Here are some ways that will help to find a file in Linux:
The “find” command feature is one the most commonly used tools to search for a file in Linux. It searches for the required file in all its directories, and with a hierarchy listed out by the user, the “find” command performs user-specified action to search for the matched file.
One can use the “find” command to list out the different files based on their historical data, permissions, type, date, size, and much more. The general syntax towards this command is as follows:
Find [options] [path…] [expression]
Options- controls the treatment of debugging options, symbolic links, and optimisation methods.
Path- helps to define the path of directories and where find will search for the files.
Expression- Helps to define the course of action with search patterns and actions separated by operators.
Find files by name
With the find command, the process includes a file, an option, and the filename. Though seemingly simple, the process takes up a lot of time. But, if you know the file name, you can directly search by using any of the options:
Name- case sensitive, eg.
find /home/linuxize -type f -name document.pdf
iname- case insensitive
find /home/linuxize -type f -iname document.pdf
The important thing to note here is that Linux is quite specific when it comes to the case. Even a single wrong character might lead to no results.
Find files by extension
Searching for files via an extension has a similar approach as searching by name. You must mention the pattern of extension followed by the backlash and asterisk symbol so that it isn’t misinterpreted when using a wildcard character.
Eg. find /var/log/nginx -type f -not -name ‘*.log.gz’
Grep tool is an indirect method to search for a file directly. It helps to generate the location of the files. If you are familiar with the files or files’ contents and know the particular term, grep can help you find all the files that include such terms.
E.g., grep -Ri ~/bin -e “An assortment”
R – means the specified directory
i- means to leave out the case distinctions
e- defines the phrase to be searched
f- sets the constraints for the field to be printed
The whereis command is commonly used to locate a command and its source of inception. It helps to list out the manual page files for the command.
E.g., whereis find
Finding files by size
This method is useful when you cannot recollect the specifics of the file you are looking for. You can use the find command to locate files of a specific size. For example, let’s assume a file with a size of 1000MB.
find / -size +1000B
It will show all the files above the specified range. You can easily browse through the output directory and get the list of potential files.
These are just the mainly used paths for Linux on how to search for file-based questions. To find a file in Linux requires some fundamental understanding of the Linux architecture and system. To have a deeper understanding, you can also go to the “find man page” to read about other options you can use to find the file in Linux.