Knowing how to find files in Linux is super handy when you need to locate a specific file quickly. There are several ways you can use to find any files you need to access in Linux. The method that works best for you will depend on how you use the Linux operating system.
However, one of the most powerful features of Linux is its core command-line interface and the wide variety of customizable commands you can use there. In our how-to guide, we cover several of the easiest and most useful ways to find files.
How to find a file in Linux
We're covering two methods for finding files in Linux. The first section will be for using a distro like Ubuntu. The second section will be using the Linux Command Line interface, which will work on any distro or without one.
How to find files in Linux: using a distro
Here we'll look at using the search functionality within a Linux distro. This guide focuses on Ubuntu, but other distros will work similarly.
1. Open the Files application
Many Linux distributions (also called distros) include a file management application which you can search in the same way you can on Windows or macOS.
To find files in Ubuntu, for example, you just need to open the Files application and select the magnifying glass icon.
2. Enter a search term in the search bar
You will then be able to enter your search term in the text box, and Ubuntu will return a list of files and folders that contain your search term.
3. Open search filter options
You can adjust your search filters by selecting the downwards arrow icon next to the search icon. You will then be able to search for specific types of files or by the age of the file.
4. Apply search filters
The results returned will match the filters you set. In the screenshot above, I searched for 'Assam,' which is the same search term I used in Step 2. In Step 2, it returned four results: two files and two folders. However, this time, I got two results because I had set the search filter to Files only.
How to find files in Linux: Command Line
Here are some basic ways to use the find command in the Linux Command Line interface, useful if this is your preferred method, or you don't have a distro with a searchable file application.
1. Using the Command Line: The find command
To search for files using Linux commands, you will first need to open your Command Line interface: press Ctrl-Alt-T to do this. Alternatively, you can search for the launcher — it may be called Terminal, Command or Shell, depending on your distro.
The basic structure of Linux find commands is:
find <starting directory> <options> <search terms>
The search term I have used in the screenshot above is
find -type d -iname Wild\ Violet
I'll break down what each part of the command is doing below:
-type d tells Linux which type of document to look for. You can use d (directory), f (file), or l (links). You can also combine them in one command, e.g. -type f,d,l.
-iname instructs Linux to ignore whether the file/directory name case matches that in the find command. If you want to see results that match the upper/lower case structure of your search term, use -iname instead here.
Wild\ Violet is the search term I'm looking for. I've used a backspace (\) because there is a space in the directory name, and the backspace tells Linux to treat the next character as a special character. You can also search for a directory or file with spaces in the name by using single or double quotes around it.
As you can see in the screenshot above, Linux returned the result Wild Violet, which was the name of the directory I was looking for.
2. Using the Command Line: Wildcards
You can use wildcards in your find command by using one or more asterisks. (*).
A wildcard is a character used to represent one or more other characters. They're often used in commands to perform operations on multiple files or directories that match a specific pattern.
I used the find command, find -type d -iname 'Top 10*' to find all directories which began with the words Top 10. Linux returned the two directories which matched this criteria.
3. Using the Command Line: Search a specific location
Both the commands above were instructions to find results in the current directory. You can also specify the location where you want Linux to search.
I used the command find ./'Top 10 Biscuit Teas' -type d,f -iname 'Custard Cream' to look inside the Top 10 Biscuit Teas directory for a file or directory called Custard Cream.
4. Using the Command Line: Searching text within files
If you want to search for text within files, you can use the grep command.
The basic format of a grep command is grep <options> <pattern> <file>
The grep command I used was grep -in "chocolate" biscuit_tea_list.txt.
-in specifies that I want Linux to ignore case sensitivity and to display the line number of each matching line.
Here's a list of grep options:
-i: Ignore case sensitivity when searching.
-v: Invert the search and display all lines that do not match the search pattern.
-c: Display only the count of matching lines.
-n: Display the line number of each matching line.
-r: Recursively search for the pattern in all files in a directory and its subdirectories.
-w: Match only whole words.
-e: Use a regular expression as the search pattern.
-f: Read the search pattern from a file.
"chocolate" is the search term that I want it to look for.
biscuit_tea_list.txt is the file I want it to look in.
As you can see in the screenshot above, Linux returned three results that matched my search criteria and provided the line numbers for each.
After following the steps above, you should feel confident about searching for files in Linux. We have only covered a few of the most basic commands for finding files in the command line interface. If you want to explore Linux command languages further, you can discover ways to finesse your find commands further. For example, you could search using time and date stamps, size, owner, or a combination of criteria. Generally speaking, the more directories and files you have, the more specific you'll want your search terms to be.
The beauty of Linux lies in its flexibility and adaptability, so you can tailor your computing experience to suit your needs.
Get the BEST of Tom’s Guide daily right in your inbox: Sign up now!
Upgrade your life with the Tom’s Guide newsletter. Subscribe now for a daily dose of the biggest tech news, lifestyle hacks and hottest deals. Elevate your everyday with our curated analysis and be the first to know about cutting-edge gadgets.
Emma Street is a freelance content writer who contributes technology and finance articles to a range of websites, including Tom's Guide, Top10.com, and BestMoney. She has over 15 years of experience working in technical development within the fintech industry. When not writing about tech, Emma can be found writing romantic fiction, reviewing films, and updating her tea blog.