🎓 A1Learner
🔍
0 of 50 lessons completed

Finding Files

Find searches a folder tree for files by name. It walks every folder below the starting point.

Find by name

Every .txt file below this folder prints, one per line.

$ cd ~/practice
$ find . -name "*.txt"

Files only

The notes folder holds two files.

$ cd ~/practice
$ find notes -type f

Folders only

Four folders sit below this folder, counting this folder itself.

$ cd ~/practice
$ find . -type d

One exact name

A name with no star matches one file only.

$ cd ~/practice
$ find projects -name "report.txt"

Example

$ cd ~/practice
$ find data -name "*.txt"

Key points

  • Use find to name files that sit deep in folders.
  • The -name option matches a file name.
  • The -type f option matches files only.
  • The -type d option matches folders only.
  • Find prints each match on its own line.
  • Put a star pattern in quotes when find uses it.
  • Find looks through a whole folder tree in one step.

In this example, find starts in the data folder. The name pattern *.txt matches three files. Each match prints on its own line.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Which command finds every .txt file below the current folder?