Get all your news in one place.
100’s of premium titles.
One app.
Start reading
Tom’s Guide
Tom’s Guide
Technology
Emma Street

How to find a file in Linux

A close up photo of a person's hands typing on a laptop keyboard.

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.

If you are using a Linux distribution like Ubuntu, you might prefer to use the intuitive Files application, which works in a very similar manner to file management systems in Windows 11 or macOS.

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

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

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.

Why not increase your Linux knowledge further with our guides on how to rename a file in Linux and how to remove a directory in Linux.

Sign up to read this article
Read news from 100’s of titles, curated specifically for you.
Already a member? Sign in here
Related Stories
Top stories on inkl right now
One subscription that gives you access to news from hundreds of sites
Already a member? Sign in here
Our Picks
Fourteen days free
Download the app
One app. One membership.
100+ trusted global sources.