How to find a File in Linux

In general, users prefer using the graphical file browser to search for a specific file. However, there exist few powerful commands that can help you find your file in your Linux system. In this tutorial, we are going to show you how to search for a missing file using various ways.

Find Files in Linux

The following methods will be covered in this guide:

  • Searching your machine using the command line
  • Search your machine using a graphical user interface

Before starting our guide, let’s first create a new file that we will try to search for in this tutorial. To make a new file, use the touch command as follows:

touch findme

Create New File
Create a New File

Search using the Command-Line

During this method, we are going to use the command line via the Linux terminal. Basically, there are two different commands to search for a file:

  • find command
  • locate command

Search using “find” command

The “find” command allows you to find files in your system. You can search by a part or full file name. Also, it can be used to search for files modified at a particular time.

For example, to search for files in the current directory that starts with the “fi” letters use the following command:

find . -name fi*

File in Current Directory

The dot or “.” here means to search in the current directory. Also, in case you need to search in a specific location, you can specify it as follows:

find /home/tuts/ -name fi*

Search For a Certain File in a Given Location
File in a Given Location

Additionally, if you do not know the file name, but you only know the file extension, then you can effortlessly search with the file extension as follows:

find /home/tuts/ -name *.png

Search For With File Extension in a Given Location
File Extension in a Given Location

Moreover, if you need to retrieve all the empty files in the current location, use the following command:

find . -type f -empty

Search For Empty Files in a Given Location
Search For Empty Files in a Given Location

Now in case, you need to search for particular files that were modified at a specific time then use the below command:

find /home/tuts/ -name *.png -mtime 2

Search For a File By Modification Date in a Given Location
Search For a File By Modification Date in a Given Location

As you can notice, the “-mtime” tag can be used to specify the files that were changed in the past two days.

Search using the “locate” Command

Using the locate command will help you search for a file. Basically, the locate command is easy to use as following:

locate findme

Search For a File Using Locate Command
Search For a File Using Locate Command

Search Using the Graphical User Interface

This is the simplest and preferred method that can be used to search for a file on your computer. First, you need to open a file browser. In most of the Linux distros, it’s called “Files” with a folder icon.

Open File Browser
Open File Browser (Ubuntu)

Then click on the search button.

Press the Search Button
Press the Search Button

Next, in the search bar, write down what you need to search for.

Search For a Certain File
Search For a Certain File

Furthermore, you can click on the drop-down arrow to search with more advanced options, including date, content, etc.

Search By Date
Search By Date

Congratulations, you have just learned how to search for a file in your Linux machine. That’s it for now, and I hope you have enjoyed it.

Leave a comment

Your email address will not be published. Required fields are marked *