Skip to content

Find Cheat Sheet

Search the filesystem by name, type, size, age, permissions, and more.

Basic Syntax

find [PATH...] [OPTIONS] [EXPRESSION]

By Name

find . -name "file.txt"           # exact name
find . -name "*.log"              # wildcard
find . -iname "*.LOG"             # case-insensitive
find . -not -name "*.bak"         # NOT matching
find . -name "*.sh" -o -name "*.py"  # either match (OR)

By Type

find . -type f    # regular files only
find . -type d    # directories only
find . -type l    # symbolic links only
find . -type p    # named pipes
find . -type s    # sockets

By Size

find . -size +100M         # larger than 100 MB
find . -size -1k           # smaller than 1 KB
find . -size +10M -size -500M   # between 10 MB and 500 MB
find . -empty              # empty files and directories

Size suffixes: c (bytes), k (KB, 1024), M (MB), G (GB).

By Modification Time

find . -mtime -1           # modified in last 1 day
find . -mtime +30          # not modified in 30+ days
find . -mmin -60           # modified in last 60 minutes
find . -newer /etc/passwd  # newer than this file
find . -mtime +7 -mtime -30  # between 7 and 30 days old

Time flags: -mtime (modification), -atime (access), -ctime (status change).

By Permissions

find . -perm 644           # exact permission 644
find . -perm -u+x          # executable by owner (at minimum)
find . -perm /o+w          # world-writable (security audit)
find / -perm /4000 2>/dev/null  # setuid files
find / -perm /2000 2>/dev/null  # setgid files

By Owner

find . -user alice         # owned by alice
find . -group developers   # owned by group developers
find . -nouser             # files with no valid owner (orphaned)

Depth Control

find . -maxdepth 1         # current directory only (no recursion)
find . -maxdepth 2         # current + one level down
find . -mindepth 2         # skip top-level, start 2 levels down

Executing Commands

# Run once per file (\; = one invocation per file)
find . -name "*.tmp" -exec rm {} \;
find . -name "*.sh" -exec chmod +x {} \;

# Run once with all files (+ = batch, like xargs)
find . -name "*.txt" -exec cat {} +

# Using xargs (most efficient for large result sets)
find . -name "*.log" -print0 | xargs -0 gzip

# Complex actions with a shell
find . -name "*.bak" -exec sh -c 'echo "Removing: $1"; rm "$1"' _ {} \;

Useful Combinations

# Find and delete old log files (> 30 days)
find /var/log -name "*.log" -mtime +30 -delete

# Find large files and report them
find ~ -type f -size +50M -printf "%s\t%p\n" | sort -rn | head -10

# Find recently modified config files
find /etc -name "*.conf" -mtime -7 -type f

# Find files with no execute bit (candidates for chmod +x)
find ~/scripts -name "*.sh" -not -perm -u+x

# Find duplicate filenames (same name, different paths)
find . -type f -printf "%f\n" | sort | uniq -d

# Disk usage of each top-level subdirectory
find . -maxdepth 1 -type d -exec du -sh {} \; | sort -h

The -prune Option (exclude directories)

# Search ~/projects but skip node_modules
find ~/projects -name "node_modules" -prune -o -name "*.js" -print

# Search but skip hidden directories
find . -name ".*" -prune -o -type f -print

Related: grep, pipes-redirection