Home Blog Certs Knowledge Base About

find

find — recursive filesystem search. Combines filters for name, type, size, time, permissions, and ownership, then runs actions with -exec.

Name & type

Search by name & type
CommandDescription
find /etc -name "*.conf"Files matching glob pattern
find /var -iname "*.log"Case-insensitive match
find / -name "passwd" 2>/dev/nullSuppress permission errors
find . -type fRegular files only
find . -type dDirectories only
find . -type lSymbolic links only
find . -type sSockets only
find . -maxdepth 2 -name "*.sh"Limit search depth to 2 levels
find . -mindepth 2 -name "*.py"Skip top level, search from depth 2
find . -not -name "*.log"Exclude a pattern
find . \( -name "*.txt" -o -name "*.md" \)OR — match either pattern
find . -name "*.py" -not -path "*/venv/*"Exclude a directory subtree

Size & time

Search by size
CommandDescription
find / -size +100MLarger than 100 MB
find / -size -1kSmaller than 1 KB
find / -size +1G -size -10GBetween 1 GB and 10 GB
find . -emptyEmpty files and directories

Size units: c bytes · k KB · M MB · G GB. Prefix + = larger than, - = smaller than.

Search by time
CommandDescription
find . -mtime -7Modified in the last 7 days
find . -mtime +30Not modified in over 30 days
find . -mtime 0Modified today (less than 24h ago)
find . -mmin -30Modified in the last 30 minutes
find . -atime -1Accessed in the last 24 hours
find . -ctime -1Inode changed in the last 24 hours
find . -newer /etc/passwdNewer than a reference file
find . -newer /etc/passwd -not -newer /tmp/refModified between two reference files

Time flags: m = modified · a = accessed · c = inode changed. time = days, min = minutes.

Permissions & ownership

Search by permissions
CommandDescription
find / -perm 644Exact permission 644
find / -perm -644At least 644 (all listed bits set)
find / -perm /111Any execute bit set (u, g, or o)
find / -perm -u=xOwner has execute bit
find / -perm -4000SUID bit set
find / -perm -2000SGID bit set
find / -perm -1000Sticky bit set
Search by ownership
CommandDescription
find / -user aliceFiles owned by user alice
find / -group staffFiles owned by group staff
find / -uid 1001Files owned by UID 1001
find / -nouserNo valid owner (orphaned files)
find / -nogroupNo valid group

Actions: -exec & -print0

-exec and actions
CommandDescription
find . -name "*.tmp" -exec rm {} \;Delete each file (one process per file)
find . -name "*.tmp" -exec rm {} +Delete — batch all files into one rm call (faster)
find . -type f -exec chmod 644 {} +Fix file permissions in bulk
find . -type d -exec chmod 755 {} +Fix directory permissions in bulk
find . -name "*.sh" -exec chmod +x {} +Make scripts executable
find . -name "*.log" -exec gzip {} \;Compress each log file
find . -name "*.bak" -deleteDelete matching files (built-in, no subprocess)
find . -name "*.conf" -exec grep -l "port 22" {} +Search inside found files
find /var/log -name "*.log" -mtime +90 -exec rm {} +Delete logs older than 90 days
-print0 & xargs -0 (safe pipes)
CommandDescription
find . -name "*.py" -print0 | xargs -0 grep "TODO"Safe pipe — handles filenames with spaces/newlines
find . -print0 | xargs -0 ls -laList every found file with details
find . -name "*.log" -print0 | xargs -0 -P4 gzipParallel compression (4 workers)
find . -name "*.py" | xargs grep "import"Plain pipe — breaks on spaces in filenames

{} is replaced by the filename. \; runs one process per file; + batches all files into one invocation (like xargs). -print0 uses null byte as separator — immune to spaces and special characters.