Four ways to find files in the Linux shell

As we all know, Linux is an operating system primarily used by geeks and developers who mainly work on the keyboard and like to write commands instead of using a graphical user interface (GUI). Unlike the Windows operating system, where most of the work is done with a few clicks of the mouse, while on Linux we have commands for everything, for example, for working with main files, compressing or extracting files, etc. These commands are executed in Linux command line, known as Terminal or Shell, A terminal or shell is a utility in Linux that is responsible for running commands.

Due to the large data in the system are tons of files. Thus, it becomes difficult for the user to find a specific file. Typically, users use the GUI to search for a file and directory, but searches using the GUI have certain limitations, such as search speed, various file types, etc. On the contrary, these commands provide the flexibility to search for files at a higher speed. with more filters, and the user will get a more meaningful result efficiently. The Linux operating system allows the user to find a specific file or folder using simple commands. In this tutorial, we will see how to find a file or folder using different commands.

Using Linux find command

The Find command on Linux is a program that allows us to go through the complete file hierarchy. The Find command allows us to search for a file and directories and supports searching by file / folder name, modification date, creation date, etc. In this lesson we will see how we can find a file using simple commands.

Step 1: First of all, open the terminal by clicking on Ubuntu Launcher and find the terminal.

Open Linux terminal

Step 2: Now click on Terminal and wait for the terminal to open.

Launch Terminal

Step 3: After opening the terminal you will have the following screen:

Linux command line

Step 4:

Example 1:

Now enter the command “find the path – FileToSearch.txt name”Where FileToSearch is the file that the user is interested in searching. Where path is the user’s default home directory. After entering, execute the command by pressing the enter key. In this example, I am looking for a file named “Sample.txtAnd the way “./”

Find a file using the search command

So, here is how you can find the file you need on Linux.

Example 2:

Here is another example of retrieving a file using the find command. We look for all text files in the user’s root directory. We used * .txt to search for all text files. Here, to find a specific file, you can use any specific file name.

Find wildcard

Using the locate command

Without a doubt, the find command is one of the most powerful and well-known command lines for finding a file. However, in the find command, we must provide a directory in which the user expects the file to be in the directory. Whereas the locate command does not have to have a directory. The user receives the file with the locate command, because this command returns the file wherever it is. Thus, in the case when the user wants to perform a high-speed search and does not know the expected directory, then the locate command is best suited in this state. In this tutorial, we will show how to use the locate command.

Step 1: First of all, open the terminal by clicking on Ubuntu Launcher and find the terminal.

Search for a terminal program

Step 2: Now click on Terminal and wait for the terminal to open.

Open terminal

Step 3: After opening the terminal you will have the following screen:

Linux command line

Step 4:

Example 1:

We just enter the location “file name”. We will get all the file paths that are named with this file name, and the user can easily track them according to his requirement.

Find files with the locate command

The user can easily find the file with this locate command.

Example 2:

Here is another example to find a file named “abc.txt”

Find an example command

The file location can be found after entering the command.

Using which team

This command finds an executable file that is additionally associated with the command / file. In fact, when we run the program, we start it from the shortcut (mainly on the desktop), but we do not know the path to the real executable file, which is located behind the actual shortcut. So which command gives us the path to the real executable. In this tutorial, we will show how we can use the which command.

Step 1: First of all, open the terminal by clicking on Ubuntu Launcher and find the terminal.

Find a terminal command

Step 2: Now click on Terminal and wait for the terminal to open.

Open Terminal

Step 3: After opening the terminal you will have the following screen:

Linux shell

Step 4:

Example1:

Now write the command “what program_name“. Here I used my firefox program to see its executable.

Four ways to find files in the Linux shell

The path to the executable will appear on the screen as soon as we press Enter.

Example 2:

Here is another example to find the location of the executable where my program / command is “date”.

Linux which example command

Using the whereis command

This command is useful for finding binary, source, and manual pages or sections of commands in the Linux operating system. Here are the steps for using the whereis command.

Step 1: First of all, open the terminal by clicking on Ubuntu Launcher and find the terminal.

Application shell foundation

Step 2: Now click on Terminal and wait for the terminal to open.

Open a terminal program

Step 3: After opening the terminal you will have the following screen:

Shell team ready

Step 4:

Example 1:

Now write the command “where is the name of the program“. Here I used the grep utility to see the path to its manual.

Use the whereis command to search for files

Example 2:

In another example, where time is another command, the path of which is determined by the following commands. This command is useful for finding binary, source, and manual pages or sections of commands in Linux.

Whereis Command Example

Conclusion

In this tutorial, we discussed basic commands to find the location of a file / folder. There are several teams to do this job. Each team has its pros and cons. Here I used the find, locate command, which is the whereis command and the command. Which commands and whereis commands are usually used to find the path to the executable file and the program / command manual, respectively, however, the find and locate commands are used to search for files in the directory.

Four ways to find files in the Linux shell

Sidebar