Linux for Developers Course
Linux for Developers
/
Intermediate

find

Definition

A highly powerful command-line utility that searches for files and directories in a directory hierarchy based on user-evaluated expressions (name, size, modification date, permissions).

Explain Like I'm New

The ultimate search engine for your hard drive. You can say 'Find me all files bigger than 50MB that were modified yesterday and end in .log', and it will find them.

Real World Example

A server runs out of space. The admin types `find /var/log -type f -size +1G`. It searches the log directory and instantly finds exactly which log files are massive and clogging the drive.

Common Use Cases

  • •Complex file searches
  • •Automated cleanup scripts

Crucial Command Flags

Flag / OptionDescription
-nameSearch by exact file name.
-typeSearch by file type (f for file, d for directory).
-mtimeSearch by modification time (e.g., -mtime -7 for last 7 days).
-execExecute a command on every file found.

Interview Questions

basic

  • How do you search for a file named exactly 'config.json' in the current directory?

intermediate

  • What does the `-exec` flag do when attached to a `find` command?

Flash Cards

Question

Search exactly?

Click to reveal answer
Answer

`find . -name "config.json"`

Question

What does -exec do?

Click to reveal answer
Answer

It allows you to execute a secondary command on every single file that `find` discovers. For example, you can use it to automatically `rm` (delete) every file it finds that is older than 30 days.