←
Command Line
/
Guided Lab Search for Files with find
60:00
Click the virtual machine below to start practicing
>_ Tekhnikum | Lab
- Setting up virtual machine…
- Preparing lab files…
- Starting terminal services…
This lab machine has stopped
Your progress through the guide is saved. Start a fresh machine to keep practicing.
Introduction
find walks a directory tree and lists everything that matches your tests. ~/project/archive is a deep, messy tree; somewhere in it is puppies.jpg.
This lab is the hands-on companion to the find lesson from Linux Journey (CC BY-SA 4.0).
Find by Name
Start the search in a directory, then give the test:
find archive -name puppies.jpg
Now copy the file you found into found/:
cp <path-you-found> found/
Find by Type and Pattern
-type d matches directories and -type f regular files. Quote patterns so the shell doesn't expand them first:
find archive -type d -name "MyFolder"
find archive -type f -name "*.log"
Find by Size and Age
-size +10M means bigger than 10 MiB. -mtime +30 means last changed more than 30 days ago:
find archive -type f -size +10M
find archive -type f -mtime +30
Summary
find dir -name pattern searches by name; quote wildcards.
-type f and -type d select files or directories.
-size +10M and -mtime +30 filter by size and age.