Mission 11 of 30

Find Command Mastery

Locate a missing file and prove the match before acting on it.

Locate files by name, type, size, time, permissions, and then act carefully on the results.

45–60 min Week 2 · Search, text, permissions, processes Ubuntu terminal
Your outcome: You can locate files without guessing where they are.
Practice inside ~/linux-practice. Check your setup before you begin. Prerequisite: Awk Fundamentals .

What you’ll practice

  • Search by name/type/size/time
  • Use -exec
  • Understand safer delete workflow

The mental model

  • find starts at a folder and walks downward.
  • Print results first before deleting.
  • -exec runs another command on each match.

Try it in your terminal

Create search lab

Safe in practice folder

Creates harmless test files.

Run from ~/linux-practice

cd ~/linux-practice
mkdir -p find-lab/subdir/nested
touch find-lab/file1.txt find-lab/file2.pdf find-lab/old.log find-lab/subdir/test.txt

Find files

Safe in practice folder

Searches by name and type.

Run from ~/linux-practice

find find-lab -name '*.txt'
find find-lab -type f
find find-lab -type d
find find-lab -empty

Act on results

Safe in practice folder

Lists matching files and prints logs before any deletion.

Run from ~/linux-practice

find find-lab -name '*.txt' -exec ls -lh {} \;
find find-lab -name '*.log' -print

Delete only after printing

Caution

Deletes only the practice .log file after you have confirmed the match.

Run from ~/linux-practice

find find-lab -name '*.log' -delete

Put it into practice

  1. Find all .txt files inside find-lab.
  2. Use -exec wc -l on matching files.

Check your result

Every match is printed before any action is taken.

Common mistakes

  • You run `find / -name '*.tmp' -delete` and watch it chew through your entire filesystem. Two problems: you started from `/` instead of your project folder, and you didn't check what matched before deleting. Run the command with `-print` first. Read the list. Then decide.
  • You type `find . -delete` thinking it deletes files in the current folder. It actually deletes everything the find command traverses — including subdirectories. Be specific: `find . -name '*.log' -delete` targets only .log files. Always name what you're looking for.

Check your understanding

Explain these in your own words. If you’re unsure, revisit the examples before moving on.

  1. Which option searches by file type?
  2. What should you do before -delete?

Your practice, your pace

Loading saved progress…

Discussion

Continue the conversation about this guide. Loading comments connects to GitHub Discussions through giscus.

Open community discussions on GitHub

Check before you copy

This command needs care. Read its context, confirm the target and location, and keep a recovery path.

Copying does not run a command.