Recursively Delete Files by Extension

Run this command to recursively delete files based on the provided extension (e.g. log):

find . -type f -name "*.log" -exec rm -f {} \;

You can remove everything after -exec (inclusive) to print the matched files to the screen (as a test run). You can change the . to be whatever directory you want to start in.

Tags: #linux #bash
Thomas Hunter II Avatar

Thomas is the author of Advanced Microservices and is a prolific public speaker with a passion for reducing complex problems into simple language and diagrams. His career includes working at Fortune 50's in the Midwest, co-founding a successful startup, and everything in between.