Whatever your distribution, knowing how to find a file in Linux is an essential skill for any fan of the open source operating system.
Whether you’re using one with a desktop GUI like Ubuntu or Mint, or running a command line-driven system like Debian, Linux makes it quick and easy to find what you need.
How to Find a File on Linux Using a Desktop File Manager
Similar in appearance to Microsoft Windows or Apple MacOS, many Linux distributions come with different desktop environments, like GNOME or KDE, to make them more user-friendly and intuitive. Although there may be slight differences between them, each Linux distribution is built on the same underlying file system.
When searching for a file on a Linux distribution with a graphical interface, the system file manager will have a built-in search operation similar to those in macOS under Windows. Open your file explorer (in the application menu on the desktop, use the search bar and enter “Files” if you have trouble finding it) and it will open in the user’s home directory.
At the top of the file explorer window, you’ll see either an address bar with a magnifying glass icon next to it, or an entirely separate search box, depending on the desktop environment you’re using. Click on the magnifying glass or click in the search field and start entering your search term.
As you type, the results field should start to be filled with partial matches, but you will still need to enter the full term you want, or close to it, to narrow this list. If the results do not automatically populate with partial results, press Enter and Linux will begin to search for the term found in the search bar.
If you don’t see a file or directory that you know should be there, chances are you will need to expand the scope of the search directory. Since Linux searches only from the current working directory and below for a file, you may need to navigate to an appropriate directory in which to start a search.
If you want to extend your search, browse the directory tree as high as you want (the root directory or / being as high as possible), then do your search.
Different interfaces handle file system navigation differently, so how going up trees may not be as intuitive as going down trees in subdirectories. Look for an up arrow next to the address bar or a side panel with essential file system locations.
Conversely, if you want to refine your search results, start browsing the sub-directories most likely to contain what you are looking for before starting a search.
This is especially useful when using very broad search terms or if you want to search for all files of a specific type (i.e. jpgs), as these tend to return lists of possible matches larger than expected.
This is because the default behavior for Linux is a so-called “greedy” search, which will be wrong on the return side of the files that could be the file you are looking for, even if it is barely qualified as a match. For example, searching for the word “term” will return “term”, “terms”, “finish”, “terminal”, “determine”, etc.
If you do not know the exact file or directory name you are looking for, you can use wildcard characters to search for partial or incomplete matches with your search term. These lists can be unintentionally large, so don’t make the search term wide enough to make the result list meaningless.
Finding a file using the Linux command line interface
The Linux command line has an intimidating reputation, especially for computer users who have used only PCs with a graphical user interface like Windows or macOS. The truth is that it’s no more complicated than text messaging with your phone, you just need to know the commands and how to use the different options available.
The Linux command you should know is find and to use it, you need to tell it where to start the search and what to search for, like this:
find directory -name filename
The directory does not have to be the current working directory, it can start a search starting in any directory from any directory. If you open a terminal window, you will start in the same home directory as the desktop file explorer, but rather than navigating to root to start a search, you can simply tell find to start in the root folder :
sudo find / -name filename
When searching from root, you will need to have root privileges to even read the contents of certain directories, so you will have to prefix your command with sudo.
The path to the directory you pass to the command can be absolute or relative, so the above command can also be written like this and will work the same way:
sudo find ../../ -name filename
You can also use the same wildcard characters for partial file names or to search for all files of a certain type and files with similar names. And you can do more with the files you find from a command line search than with a GUI file explorer search.
The command line allows you to pass the results of a search directly into another Linux command as input. For example, you can find all files of a certain type and feed them into a shell script that can rename them all to make them easier to organize or remove unnecessary duplicates.