• About
  • Editorial policy
  • Contact
  • Privacy
  • Legal
  • Cookie settings
Monday, November 2, 2026
  • Login
PacketNebula
  • Home
  • News
  • Tools
    • Network
    • Security
    • Developer
    • Sysadmin
    • SEO
    • Email & DNS
  • Guides
  • Trackers
    • LLM API pricing
    • Open-weight models
    • Retirements calendar
    • Infrastructure deals
  • About
  • Download
No Result
View All Result
PacketNebula
No Result
View All Result
Home Sysadmin

How to find files with find on Linux

by Stéphane Cardon
7 October 2026
in Sysadmin
0
Magnifying glass held over an old postage stamp collection, showing a Deutsche Post 1 Reichsmark stamp enlarged

Image: Heptagon / Wikimedia Commons, Public domain

Share on FacebookShare on Twitter

A disk fills up, or a config file vanishes, and suddenly we need one file out of fifty thousand. find is the tool for that, and its shape never changes: find, then where to look, then what to match. find . -name '*.log' lists every .log file under the current folder; swap the dot for /var/log to search there instead. From there we filter. -type f keeps it to files (d for directories), -size +100M pulls out the big ones. -mtime -7 catches anything changed this week. Then we act on the matches with -delete or -exec. It ships on every Linux and macOS box, no install. Here's the everyday syntax we actually reach for, plus the safe way to delete matches without wiping the wrong tree.

The short answer

find . -name '*.log' lists matching files below the current folder. Narrow with -type and -size (or -mtime for age), then act with -delete or -exec. Run it without -delete first and read the list. Every time.

-namematch by name
-size / -mtimeby size or age
-deleteact on matches
Answer card showing find . -name to locate files, filtering by type, size and mtime.
Where to look, what to match, then what to do. That’s the whole shape of find.

Find by name, size or age

Linux
find . -name '*.log'

That walks the current folder and everything under it. Case getting in the way? -iname matches without caring about it.

Linux
find /var/log -name '*.log' -mtime +30

That one lists logs nobody has touched in a month. And when something’s eating the disk, we match on size, files only:

Linux
find . -type f -size +100M

Act on the results, carefully

Linux
find . -name '*.tmp' -delete

Run it once without -delete and read the list. Every line. find does exactly what we tell it, including deleting a tree we never meant to touch. It happens, and it’s a bad afternoon.

Terminal showing find by name listing log files, find with -mtime for old logs, then find with -delete.
List, narrow, then act. The -delete goes on last, after you trust the list.

Other handy filters

-type d finds directories, -empty finds empty files or folders. -newer ref matches anything modified more recently than a reference file, and -exec command {} + runs a command on every match when -delete isn’t what you need.

Three things make find pleasant rather than painful, and none of them are obvious from the manual page.

First, -maxdepth has to come before the other tests or find complains, and it saves you from walking an entire filesystem when you only meant the current folder. Second, permission errors will flood your terminal on any system-wide search, so send them away with 2>/dev/null and read what’s left. Third, excluding a directory needs -prune rather than a filter, which is the syntax everybody looks up every single time.

Linux and macOS
find . -maxdepth 2 -name '*.log' 2>/dev/null
Linux and macOS
find . -path ./node_modules -prune -o -name '*.js' -print

One more, on -exec. Ending it with ; runs your command once per match, which on ten thousand files means ten thousand processes. Ending it with + batches the matches into as few invocations as possible, exactly like xargs does, and it’s dramatically faster. We use + unless the command genuinely needs one file at a time.

The syntax never quite becomes muscle memory. It’s the order that catches us out, because the path comes before the tests and the action goes last, and getting that wrong accounts for most of the errors you’ll ever see from this command.

Frequently asked questions

How do I find a file by name?

find . -name '*.conf' lists every .conf file under the current directory. -iname does the same job but ignores case. And keep the quotes around the pattern, otherwise the shell expands the star before find ever sees it.

How do I find files bigger than a certain size?

It's -size plus a suffix: -size +100M means larger than 100 MB, -size -1k means smaller than 1 KB. We always add -type f too, so it matches files only, not directories.

How do I find files changed recently?

Days are the unit for -mtime: -mtime -7 means modified in the last 7 days, -mtime +30 means older than 30 days. Need minutes instead? -mmin works exactly the same way.

How do I delete the files I found, safely?

Run the find without -delete first and actually read the list. Once it's exactly right, append -delete (or -exec rm to act on each one). Deleting blind is how people erase the wrong tree. Look first, every time.

Tags: cliguidelinux
ShareTweet
Previous Post

How to search text in files with grep

Next Post

How to manage services with systemctl

Stéphane Cardon

Stéphane Cardon

Network cybersecurity engineer: architecture, LAN and WLAN, system administration. He runs PacketNebula, where he publishes the tools and answers he wanted for his own work.

Next Post
Rows of illuminated server racks in the NOIRLab computer server room in Tucson, Arizona

How to manage services with systemctl

Free tools

  • IPv4 subnet calculator
  • DNS lookup
  • SSL certificate checker
  • HTTP headers checker
  • SPF, DKIM and DMARC checker
  • JWT decoder
  • Cron expression builder
  • Chmod calculator
  • Password generator

All 24 tools →

Guides to keep handy

  • Flush the DNS cache on Windows
  • Kill the process using a port
  • Generate an SSH key
  • Secure a new Ubuntu VPS
  • Find files on Linux
  • Extract and create tar.gz

More guides →

Who writes this

Stéphane Cardon, network cybersecurity engineer. Architecture, LAN and WLAN, system administration. PacketNebula holds the tools and answers he wanted for his own work.

About this site →

  • About
  • Editorial policy
  • Contact
  • Privacy
  • Legal
  • Cookie settings

Copyright © 2026 Stephane Cardon.

No Result
View All Result
  • Home
  • News
  • Tools
    • Network
    • Security
    • Developer
    • Sysadmin
    • SEO
    • Email & DNS
  • Guides
  • Trackers
    • LLM API pricing
    • Open-weight models
    • Retirements calendar
    • Infrastructure deals
  • About
  • Download

Copyright © 2026 Stephane Cardon.

Cookies, your call

We use Google Analytics to see which pages get read. Once our AdSense application is approved, articles and guides will carry Google ads. Nothing runs until you say yes, and nothing runs on the tool pages. Details