AI Hints
Home›Linux Tutorial›Finding Files
Linux · Lesson 38 of 120

find: Searching for Files

By name.

⏱ 2 min read▶ Video at 48:01🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

You know a file exists somewhere, but you can't remember where you saved it. Instead of opening folder after folder, let the find command search the tree for you.

find: Searching for Files
From the video: find: Searching for Files
  • Where did I save it?
  • Don't search by hand
  • find searches the tree

Find by name

Find takes a starting folder, and then what to look for. Find dot, dash name, style dot CSS, searches the current folder, and every folder inside it. It prints the path to the file it found, deep inside projects.

Terminal
find . -name style.css
./projects/website/css/style.css

Find with a pattern

You can use wildcards too. Put the pattern in quotes, so find gets the star, not the shell. Every file whose name ends in dot TXT, anywhere in your home. Dash I name ignores capital letters, so dash I name, cv star, finds cv dot TXT, however it's written.

Terminal
find . -name "*.txt"
./Documents/cv.txt
./Documents/report.txt
./Music/playlist.txt
./todo.txt
./notes.txt
find . -iname "CV*"
./Documents/cv.txt

Searching the whole system

To search the whole computer, start from slash. But many folders belong to other users, or to the system. Find will print permission denied for those. Adding two greater than slash dev slash null hides those error messages. We'll learn exactly how that works in a later lesson.

keyvalue
find / -name xsearch everything
Permission deniedfolders you can't read
2>/dev/nullhide the errors
Start smallsearch ~ first

Summary

Find, a starting folder, and dash name, searches a whole tree. Quote your wildcards. Next, finding files by type, size, and age.

Key takeaways
  • find . -name file
  • find . -name "*.txt"
  • -iname ignores case
Next up: find: Type, Size and Time — more ways to search