Advanced find by Size, Time & Exec (-size, -mtime, -exec)
Concept & Overview
Beyond basic filename queries, find is a powerhouse filter engine for automated system cleanup and log rotation:
- -size +50M: Filters for files strictly larger than 50 Megabytes (+ for greater than, - for less than).
- -mtime -7: Filters for files modified within the last 7 days.
- -exec : Passes all matched files directly into a command in batches, replacing {} with matched file paths.
Combining these allows single-line system maintenance, such as finding and purging runaway logs: find /var/log -size +50M -exec rm {} +.
find /var/log -size +50M -mtime -7, then delete the oversized crash dump using find /var/log -size +50M -exec rm {} +.Command Syntax Reference
| Command / Syntax | Description |
|---|---|
find /var/log -size +50M -mtime -7 | Find files larger than 50MB modified within 7 days |
find /var/log -size +50M -exec rm {} + | Find and automatically remove files larger than 50MB |
Verification Objectives
These conditions will be automatically verified when you run commands inside the interactive terminal simulator:
- ○Filter files by size and modification time with find
- ○Delete oversized log using find -exec rm
Ready to complete Quest 85?
Test your skills live in the browser terminal with an emulated Linux filesystem, real-time command evaluation, and instant step-by-step hints.