Linux Find files

As we all know Linux is an operating system mostly used by the Geeks and developers which are mostly a keyboard person and love to write commands instead of using Graphical User Interface (GUI). Unlike Windows operating system, where most of the work done is with few clicks while in Linux we have commands for everything like basic file manipulations, compression or extraction of files etc. These commands run on the Linux command line which is known as Terminal or Shell. The Terminal or shell is a utility in Linux which is responsible to run the commands.

Due to the larger data, tons of files are there in a system. So, it becomes difficult for a user to find out a particular file. Usually, users take the help of GUI for searching a file and directory however the search using graphical user interface has certain limitations such as searching speed, different file types etc. On contrary, these commands provide flexibility to search the files at higher speed with much more filters, and the user will get more meaningful result efficiently. Linux operating system allows the user to find a specific file or folder using simple commands. In this tutorial, we will see different how to find a file or folder using different commands.

Using Linux find command

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

Step 1: First of all, open Terminal by clicking on Ubuntu launcher and search for Terminal.

Open Linux Terminal

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

Start the Terminal

Step 3: Once the terminal is opened, you will have a screen like this:

Linux command prompt

Step 4:

Example 1:

Now type the command “find path –name FileToSearch.txt” where FileToSearch is the file a user is interested to search. Where path is default user home directory. Once typed, execute the command by pressing enter key. In the example, I am searching a file named “Sample.txt” and path is “./”

Find file with find command

So, this is how you can find your required file in Linux.

Example 2:

Here is another example to attain a file using the find command. We are searching all text files in user’s root directory. We have used *.txt for searching all text files. Here to find a specific file you can use any particular name of a file.

Find wildcard

Using locate command

No doubt find command is one of the most powerful and a famous command line to search a file. However, in find command, we have to provide the directory in which the user expects the file to be located in a directory. Whereas, the locate command does not need to have a directory. The user gets the file by “locate” command because this command returns the file wherever it is located. So, in a case where a user wants to have a high-speed searching and does not know the expected directory, then locate command suits best in that condition. In this tutorial, we will show how to use “locate” command.

Step 1: First of all, open Terminal by clicking on Ubuntu launcher and search for Terminal.

Search the terminal program

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

Open terminal

Step 3: Once the terminal is opened, you will have a screen like this:

Linux command prompt

Step 4:

Example 1:

We just enter the locate “file name”. We will get all the paths of the file that are named with this file name and the user can easily trace them, as per his demand.

Find files with locate command

The user can easily find the file he needs by this locate command.

Example 2:

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

Locate command example

Location of the file can be found once the command is entered.

Using which Command

This command locates an executable file that is associated further with a command/ file. In reality, when we run a program, we run it from a shortcut (desktop mostly), but we don’t know the path of an actual executable file that lies behind the actual shortcut. So, which command gives us the path to an actual executable file. In this tutorial, we are going to show how can we use the which command.

Step 1: First of all, open Terminal by clicking on Ubuntu launcher and search for Terminal.

Find terminal command

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

Open the Terminal

Step 3: Once the terminal is opened, you will have a screen like this:

Linux shell

Step 4:

Example1:

Now, write the command “which programName”. Here I have used my program firefox to see its executable file.

The path of executable file will appear on the screen once we press enter.

Example 2:

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

Linux which command example

Using whereis Command

This command is helpful to locate binary, source and manual pages or sections of commands in Linux Operating system. Here are the steps to use “whereis” command.

Step 1: First of all, open Terminal by clicking on Ubuntu launcher and search for Terminal.

Fund shell application

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

Open the terminal program

Step 3: Once the terminal is opened, you will have a screen like this:

Shell command ready

Step 4:

Example 1:

Now, write the command “whereis programName”. Here I have used a utility grep to see the path of its manual.

Use whereis command to find files

Example 2:

In another example, where time is another command whose path is gained by following commands. This command is helpful to locate binary, source and manual pages or sections of commands in Linux.

Whereis command example

Conclusion

In this tutorial, we have discussed the basic commands to find the location of a file/ folder. There are multiple commands to do this job. Each command has its own pros and cons. Here, I have used find command, locate command, which command and “whereis” command. Which and whereis commands are generally used to find the path of the executable file and manual of a program/command respectively however, the find and locate command are used to search the files presented in the directory.

Four ways to find files on the Linux shell