How to Use The Linux Find File Command

Quickly search files on the Linux desktop

A desktop computer, keyboard, and mouse

Pixabay

 

You know you saved that file on your desktop. But where? If you’re on the Linux platform, you have a number of tools at your disposal. These tools are not only incredibly powerful, but easy to use, both those on the command line or in the graphical user interface (GUI).

We’re going to walk you through the process of locating files on your computer using the find command and the GNOME Desktop Environment. 

Version Information

For the purposes of this tutorial, we used System76’s Pop!_OS, running GNOME 3.32-1. The version used for the find command isn’t important (as the command has been around for a very long time). The version of GNOME you use could cause some slight variations in the process (especially if you’re using a much older version of the desktop).


The find Command

The first method we’ll use is the find command. This command is very powerful and its usage can get rather complicated. However, the basic usage of the find command is actually pretty simple. This is especially true when you know the name of the file for which you’re looking. Let’s say you have a file named lifewire somewhere in your ~/home directory (you just can’t remember where you put it). If you have a lot of sub-directories, locating that file can be a challenge.

With find, it’s actually pretty easy. Here’s how you manage this task:

  1. Open a terminal window.

  2. Change into your home directory with the command cd ~/.

  3. Locate the file with the command find . -name lifewire.

    Screenshot of the basic find command.
  4. Open the file in question.

Let’s talk about the format of the above command:

  • find - the actual command
  • . - instructs find to look in the current directory and all sub-directories.
  • -name - instructs find that what follows is the name of the file to be located.
  • Lifewire - is the name of the file we’re searching for.

The find command will immediately dive into the current directory and then search all sub-directories for any file matching (in the case of our example) lifewire. If it locates anything, find will list out the directory housing the file in question.

Permission Warning

Should find attempt to dive into a directory you don’t have permission for, it will report that with a Permission denied warning.

What if you’re not sure of the full name of the file? Fortunately, find allows the use of wildcards.

What Are Wildcards?

In computing terms, a wildcard is a character that can be substituted for any number of other characters. For instance, you know the file you’re looking for begins with the word life, but you can’t remember the rest of the name. You can use the * wildcard like so - life*. Wildcards can also be used in the middle of a string of characters. Say you can’t remember if the file is lifewire, lifetire, or lifedire. You could use the * wildcard like so - life*ire.

So to find that lifewire file, when you’re not sure how you spelled it, you could issue the command find . -name life*ire. The results of the command will be similar to those when using the full file name.

Screenshot of using a wildcard with find.

That same wildcard could be used if you’re looking for a specific file type. Say, for instance, you wanted to search for all .jpg images. You could issue the command find . -name *.jpg to find what you’re looking for.

Searching From the Desktop

Now we get to the easy part—searching from the GNOME desktop. There are two ways to successfully find what you’re looking for. The two methods are:

  • From the GNOME Dash
  • From the file manager

The more reliable of the two methods is via the file manager. Although searching from with the GNOME Dash does work, there are occasions when it will fail to find files. The Nautilus file manager, on the other hand, never fails. Let’s find out how to search for a file using that method. Here’s how:

  1. Open the Nautilus file manager.

  2. Navigate to the top level directory relative to what you are searching for. For example, if you know the file is in a sub-directory located in your home directory, navigate to Home. 

    Screenshot of the Nautilus file manager in the home directory.
  3. Click the search icon.

    Screenshot of the search icon in Nautilus.
  4. Type the name of the file you’re looking for.

    Screenshot of searching for a filename in Nautilus.
  5. Once the results appear, double click the file in question to open it.

Searching from the GNOME Dash does work (and generally works well). You’ll find this method coming up a bit short if you’re searching for a file created from the command line. All other files, however, are usually found without a problem. 

To search for a file from within the GNOME Dash, follow these steps:

  1. Click Activities to open GNOME Dash.

  2. Type the name of the file you’re searching for.

    Screenshot of finding a file within GNOME Dash.
  3. When the file appears below the search bar, click it to open.

And that’s all there is to searching for a file from both the command line and the GNOME Desktop. Never worry that you’ll not be able to locate those files on the Linux desktop, as they are only a quick search away.