Search

INPUT · Slides

Track it down by name

01 / 08

Looking with your eyes is the slowest way

Once you have a lot of files, ls then cd then ls again gets painful fast.

Three levels of boxes with ten things in each is over a hundred places to peek into. Once the numbers grow, looking with your eyes is the slowest method there is.

This chapter hands the looking to the machine. find searches by name, grep searches by the text inside.

02 / 08

find — dive down and look

The shape of find is this.

find where-from -name what

Most of the time "where from" is . (right here). From there it dives into every box underneath and looks.

Unlike ls, depth is not your problem. However many levels there are, it goes down them for you.

~ $ find . -name memo.txt./memo.txt./work/memo.txt./work/2026/spring/memo.txt

03 / 08

What it finds comes out as directions

What comes out is not a name but the directions to get there (a path).

When you see ./work/2026/spring/memo.txt, you also know where it lives. So once you have found it you can hand it straight to cat.

It starts with a . because it means "the directions as seen from where the search started". Write find /home/learner -name ... and the results start with /home/... instead.

04 / 08

* stands for "something"

When you only remember part of a name, use *. It means any run of characters.

  • *.txt — things ending in .txt
  • memo* — things starting with memo
  • *memo* — things with memo somewhere in them

One warning. You need to wrap it in quotes. Without them the shell expands the * before find ever sees it.

~ $ find . -name '*.md'./work/2026/spring/report.md./photos/sea/autumn.md

05 / 08

-iname ignores upper and lower case

-name cares about upper and lower case. -name memo.txt will not find Memo.txt.

When you want to search without caring, use -iname. The i is the first letter of insensitive.

File names people made up are all over the place on capitals, so when in doubt, -iname is the safer bet.

06 / 08

Search from a chosen place

Write the name of a box instead of . and it only searches below that.

find work -name '*.txt' only looks inside work. It does not search anywhere irrelevant, so it is quicker and the result is easier to read.

Narrowing where you look is the single best trick when hunting for something.

~ $ find work -name '*.txt'work/memo.txtwork/2026/plan.txtwork/2026/spring/memo.txt

07 / 08

Cutting off the depth with -maxdepth

find goes all the way down, so with a deep tree you can get far too many results.

Add -maxdepth 1 and you get only where you are standing; -maxdepth 2 gets you one level down.

There is a rule that -maxdepth goes before the conditions, so you write them in the order find . -maxdepth 1 -name ....

~ $ find . -maxdepth 1 -name '*.txt'./memo.txt

08 / 08

Now have a go

This room has three files called memo.txt, at three different depths, deliberately arranged so ls cannot show them to you at once.

find gets all of them in one line. The order can vary between machines, so any order counts as right.