The Boring Infra ▍

LINUX · COMMAND LINE

How to find a file on linux when you only remember the name

16 November 2026 · 10 minute read

You know the file exists. You know its name. You don't know which of the four places it could be in, and clicking through directories is a losing game on a machine with a home directory this deep. Mine has 2,144 files called SKILL.md on it, spread across a dozen tools that each ship their own, and the one I actually want is a specific one. The terminal answer is find, and it's one line.

To find a file in linux, run find . -name "filename" from the directory you want to search, and swap in -iname when the case is uncertain. Add -type, -size or -mtime to narrow the search, and widen the depth before you conclude the file is gone.

find searches the tree by name

find takes a starting point, then a test, and prints everything that passes. The starting point is usually a dot for the current directory or a real path like /etc. The test here is -name with a quoted pattern.

$ find . -name "q3.csv"
./reports/q3.csv

The part that catches people is how far find walks to answer that one line. It descends every subdirectory under the starting point, so on a large tree the answer takes seconds rather than milliseconds. The pattern is a shell glob, so -name "*.log" matches every log file in the tree and -name "q3*" matches anything starting with q3. A pattern never contains a slash, because -name only ever sees the base name.

Use -iname when you aren't sure of the case

-name compares the name exactly, capitals included. Half the time the file you want is named one way on your laptop and another way on the server. -iname is the same test without the case sensitivity.

$ find . -iname "Q3.CSV"
./reports/q3.csv

I type this one first now. A name search that fails on a capital letter tells you nothing about whether the file exists.

Narrow it by type, size, or age

A name alone is often too loose, and find has a test for almost everything you would want to narrow on. Type separates files from directories. Size and modification time handle the rest.

$ find . -type d
.
./archive
./reports
./reports/2026
./logs

Change -type d to -type f and you get regular files only, which is what you want when you're counting or piping into another command. Then the useful pair, size and age.

$ find . -type f -size +0 -printf "%s\t%p\n" | sort -n
2	./archive/old.tar.gz
5	./reports/2026/oct.csv
6	./logs/app.log
6	./notes.txt
6	./reports/q3.csv

$ touch -d '3 days ago' archive/old.tar.gz

$ find . -type f -mtime -1
./reports/q3.csv
./reports/2026/oct.csv
./notes.txt
./logs/app.log

Those sizes come from a five file fixture with a few bytes written into each, which is why every number is small. The first command prints size in bytes next to each path, and the +0 means any file with something in it. Sizes round up to whole units, and the suffix matters. M is mebibytes, so -size +100M means strictly more than 104,857,600 bytes rather than 100 million. A file of exactly that size doesn't match the plus form, and dropping the plus is how you ask for it. -mtime -1 means modified within the last 24 hours, and the minus sign is doing the work there. +1 is the other direction, more than one full day old, which in practice needs about two days because the fractional period is discarded.

Walking a whole tree is the point, and it's also the cost. Two flags keep the search small. Give it a real starting path, and cap the depth.

$ find /var/log -maxdepth 2 -name "*.log" 2>/dev/null | sort | head -5
/var/log/alternatives.log
/var/log/apport.log
/var/log/apt/history.log
/var/log/apt/term.log
/var/log/auth.log

-maxdepth 2 means the starting directory counts as level one, so this looks at files in /var/log and one level below it. Those filenames are Ubuntu's, so on RHEL the same search finds messages and secure instead of auth.log and syslog, and the shape of the answer doesn't change. Without the cap find keeps descending, and running it from / means walking every container layer on the box. The 2>/dev/null is there because /var/log has directories this user can't read, and their complaints would otherwise print above the results. The exit status is still one, because those errors happened, so a script that checks $? sees a failure even though the matches are right. On an unfamiliar host, throw those errors into a file instead of into the void with 2>/tmp/find.err, because permission holes mean the tree you searched wasn't the whole tree. Add -xdev when the path can cross into another filesystem, or a search under /var will wander into a backup mount and sit there for ten minutes.

The errors are worth reading once, because each one names a path find couldn't enter, in a line that ends with Permission denied. That line is a gap in coverage, not a failed search. Every match printed around it's still valid, and it tells you which part of the tree the search never saw.

The search you actually run

The abstract examples stop being abstract the first time you go looking for a config file that a tool buried somewhere under your home directory. This is the real one from this box, hunting the file that holds an agent's identity.

$ find ~/.hermes -maxdepth 2 -name "SOUL.md"
/home/deploy/.hermes/SOUL.md
/home/deploy/.hermes/hermes-agent/SOUL.md

Two paths, both plausible, and the one you want depends on which directory the process reads from. Now the same idea with a file name that turns out to be everywhere.

$ find ~ -name "SKILL.md" | wc -l
2144

$ find ~/.hermes/skills -name "SKILL.md" | wc -l
269

Two thousand one hundred and forty four files with that name on one machine, and only 269 of them are the ones I care about. The rest arrived with packages, because every tool that borrows the skills convention ships its own copies inside its install directory and inside node_modules. This is why a search from ~ and a search from the right directory give wildly different answers, and why the starting point is the most important thing you type.

Then the trap that catches everyone once. Tightening the depth looks like it should help.

$ find ~ -maxdepth 3 -name "SKILL.md" | wc -l
0

Zero. There are 2,144 of those files and a three level limit finds none of them, because the useful ones sit deeper than three directories. A find that returns nothing isn't evidence the file is absent. It's evidence about where you looked.

The other habit worth forming is searching for a directory instead of a file, since tool configs tend to live in one.

$ find ~/code -type d -name ".claude" 2>/dev/null | head -3
/home/deploy/code/project-a/.claude
/home/deploy/code/app-cards/node_modules/tailwindcss/node_modules/resolve/.claude
/home/deploy/code/app-cards/node_modules/postcss-import/node_modules/resolve/.claude

One real project directory and two that came in with a dependency. Same lesson as the SKILL.md count, one level different. When a search returns junk, the fix is usually a narrower starting path rather than a more complicated test.

Act on what you find

Printing paths is only half of it. -exec runs a command against each match, and the braces stand for the current file. It's also the portable choice, because -printf and -delete are GNU extensions and busybox doesn't have them, which matters on Alpine and most distroless images.

$ find . -name "*.csv" -exec ls -l {} \;
-rw-rw-r-- 1 deploy deploy 6 Nov 17 17:57 ./reports/q3.csv
-rw-rw-r-- 1 deploy deploy 5 Nov 17 17:57 ./reports/2026/oct.csv

The escaped semicolon ends the command, and it needs the backslash because the shell would otherwise eat it. Never build an -exec rm or -exec mv line against a pattern you have not just printed. Run the same find without the -exec first, read the list, then add the action.

locate answers faster from an index

locate doesn't walk anything. It searches a database built by updatedb, usually on a nightly timer, and returns paths in milliseconds. The catch is that it has to be on the machine first.

$ command -v locate
$ echo $?
1

Nothing printed and a status of one, which is the answer on a minimal image more often than not. locate ships in the mlocate or plocate package, and plenty of cloud images leave it out. Install it first (apt install plocate or dnf install plocate), run updatedb once to build the index, and then locate app.log prints the full path in milliseconds. A fresh install with no updatedb yet returns nothing, which looks like a broken command and is really an empty database.

The trade is freshness. A file created since the last database rebuild is invisible to locate, so an empty answer isn't proof the file is gone.

Which one to use, at a glance

Match the test to what you actually know about the file.

CommandWhat it doesReach for it when
find . -name "x"Searches the tree for an exact nameYou know the name and the case
find . -iname "x"Same search, ignores caseYou know the name, not the capitals
find . -type dPrints directories onlyYou want folders, not files
find . -type f -size +100MPrints regular files strictly larger than 100 MiBSomething is filling the disk
find . -mtime -1Prints files changed in the last 24 hoursYou want what changed recently
find /path -maxdepth 2 -name "*.log"Searches a bounded part of the treeThe tree is huge and you know roughly where to look
find . -name "x" -exec cmd {} \;Runs a command on each matchYou need to act on all of them
locate xSearches the updatedb indexThe file isn't new and speed matters

Verify it works

Build the same tree first, then run the checks against it. The last command in the setup moves one file's timestamp back three days, so the count at the end has something to exclude.

$ mkdir -p reports/2026 logs archive
$ touch notes.txt reports/q3.csv reports/2026/oct.csv logs/app.log archive/old.tar.gz
$ touch -d '3 days ago' archive/old.tar.gz

$ find . -name "q3.csv"
./reports/q3.csv

$ find . -iname "Q3.CSV"
./reports/q3.csv

$ find . -maxdepth 1 -type f
./notes.txt

$ find . -type f -mtime -1 | wc -l
4

The name search and its twin that ignores case return the same path. The -maxdepth 1 run prints only what sits in the top directory, so everything under reports is absent. The count is four because the backdated archive drops out.

The honest caveat

find reports every directory it can't read, and on a locked down box those messages can be longer than the results. They go to standard error, so 2>/dev/null hides them and the matches stay correct. Hiding them is fine. Believing the result is complete when the search never entered half the tree isn't.

Two more flags matter before you write a find line into a script. -path matches the whole path instead of the base name, so you can find one branch of the tree without matching the same name elsewhere. -delete removes matches directly, which is find's own way of doing what rm does once you have filtered the list. Test with -print before you swap in -delete, and know that -delete turns on -depth by itself, so the listing you ran first walks the tree in a different order than the delete will.

On the clusters I run, find is the command I reach for when a node's disk looks full and the numbers don't add up. The pod list is small, the filesystem isn't, and something wrote a file somewhere nobody was watching. Once you have the paths, du tells you what they weigh and df tells you whether the filesystem is actually out of room.

The boring conclusion

Finding a file is one command with a starting point and a test, and the rest is choosing the test. -name for the name, -type, -size and -mtime to narrow, -exec when you need to act.

What's the file that always goes missing on your boxes?

Frequently asked questions

Why does find return no results?

Usually because the starting point or the depth limit is wrong, not because the file is missing. A maxdepth limit of three finds nothing in a tree where the files sit five levels down, and a search from the wrong directory can't see the file at all.

How do I find a file by name regardless of case?

Use -iname instead of -name. find . -iname "q3.csv" matches q3.csv, Q3.CSV and Q3.csv in one pass. The -name test is case sensitive, so it only finds the exact spelling.

How do I find files larger than 100 MB?

Add -size +100M. find /var -type f -size +100M prints files above 100 mebibytes. The suffix is binary, so M means 1024 by 1024 bytes, and sizes round up to whole units.

What is the difference between find and locate?

find walks the filesystem every time, so it's always current and slower. locate reads a database built by updatedb, so it answers fast and only knows files that existed when that database was last rebuilt.

How do I run a command on every file find returns?

Use -exec. find . -name "*.csv" -exec ls -l {} \; runs ls -l on each match. The braces stand for the current file and the escaped semicolon ends the command.

Resources

These are the manuals the commands actually follow, so the flags behave here the way they behave on your box.

This builds on how to check the last 20 lines of a file, which is how you read what you just found.

The next move is renaming what find returned, which is mv, covered in how to rename a file on linux.