How to Find Files in Ubuntu Linux Terminal Using the find Command

Navigating a complex Linux server without a graphical file manager can be intimidating. If you forget exactly where you saved a configuration script or downloaded a massive log file, manually checking every folder using cd and ls is impossible. Fortunately, Ubuntu Linux includes a built-in, incredibly powerful search tool called the find command, which allows you to locate files based on their name, size, type, or even the date they were last modified.

How to Find a File by its Exact Name

The most common use of the find command is searching for a file when you know its exact name. The syntax requires you to specify where to start searching, followed by the -name flag.

find /home/user -name "server_config.txt"

In this example, the command will look inside the /home/user directory (and all folders inside it) for a file named exactly “server_config.txt”. If it finds it, it will print the full, absolute path to the file on your screen.

If you want to search the entire hard drive, you start the search at the root directory (/). Because searching the root directory requires scanning system folders, you must use sudo:

sudo find / -name "server_config.txt"

How to Find Files Using Wildcards (Partial Names)

If you only remember part of a file’s name, or if you want to find all files of a specific type (like all Python scripts), you can use the asterisk (*) wildcard.

To find every single .py file inside your Documents folder, you would type:

find /home/user/Documents -name "*.py"

To find any file that has the word “backup” somewhere in its name, regardless of what comes before or after it:

find / -name "*backup*"

How to Find Files by Size

If your server is running out of storage space and you want to locate massive, forgotten log files to delete, you can use the -size flag. You use + for “greater than” and - for “less than,” followed by the unit (k for kilobytes, M for megabytes, G for gigabytes).

To find all files larger than 500 Megabytes in the entire system:

sudo find / -size +500M

To find files that are exactly 10 Gigabytes:

sudo find / -size 10G

How to Find Files by Modification Date

If a web application crashed yesterday and you want to find out which configuration files were altered recently, you can search by time using the -mtime (modification time in days) or -mmin (modification time in minutes) flags.

To find all files in the /etc directory that were modified in the last 24 hours (less than 1 day ago):

find /etc -mtime -1

To find files modified exactly 7 days ago:

find /home/user -mtime 7

To find files modified in the last 30 minutes:

find /var/log -mmin -30

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.