On this page 16 sections
  1. How find works
  2. Search by name
  3. Search by type
  4. Search by size
  5. Search by owner or group
  6. Search by permissions
  7. Find writable files for the current user
  8. Search by modification time
  9. Modification, access and metadata time
  10. Search newer than another file
  11. Limit recursion depth
  12. Exclude directories with prune
  13. Combine conditions
  14. Execute commands on results
  15. Use -ls and -printf
  16. Useful enumeration searches
01

How find works

find recursively walks a directory tree and evaluates each file against one or more conditions. The basic structure is: find <path> <conditions> <actions>. Multiple conditions can be combined to build precise searches.

Basic syntax
find /path -type f -name "*.conf"
02

Search by name

-name performs case-sensitive filename matching while -iname ignores case. Wildcards should normally be quoted so the shell does not expand them before find receives them.

Find configuration files
find /etc -type f -name "*.conf"
Case-insensitive search
find /var/www -type f -iname "*.php"
Find exact filename
find / -type f -name "id_rsa" 2>/dev/null
03

Search by type

-type restricts results to a specific filesystem object. The most common values are f for regular files, d for directories and l for symbolic links.

Files
find /opt -type f
Directories
find /opt -type d
Symbolic links
find / -type l 2>/dev/null
04

Search by size

-size searches by file size. Prefix + means larger than the specified size and - means smaller. Common suffixes include c for bytes, k for KiB, M for MiB and G for GiB.

Files larger than 100 MB
find /var -type f -size +100M 2>/dev/null
Files between 10 MB and 100 MB
find / -type f -size +10M -size -100M 2>/dev/null
05

Search by owner or group

-user and -group locate files associated with a specific account or group. -nouser and -nogroup are useful for identifying files whose original UID or GID no longer maps to an existing account.

Files owned by john
find / -user john 2>/dev/null
Files owned by root
find /opt -type f -user root -ls
Files without a valid owner
find / -nouser 2>/dev/null
06

Search by permissions

-perm allows searches using Unix permission bits. An exact mode matches only that permission set, while the - prefix means all specified bits must be present.

SUID binaries
find / -type f -perm -4000 2>/dev/null
SGID binaries
find / -type f -perm -2000 2>/dev/null
World-writable files
find / -type f -perm -0002 2>/dev/null
World-writable directories
find / -type d -perm -0002 2>/dev/null
Searching for files with edit permissions
find / -not -type l -perm -o+w
07

Find writable files for the current user

-writable checks whether the current process can write to an object. This is often more practical than manually interpreting permission bits because ACLs and the current identity may also affect access.

Writable files in /opt
find /opt -type f -writable -ls 2>/dev/null
Writable directories
find / -type d -writable 2>/dev/null
08

Search by modification time

-mtime works in 24-hour units. -mmin uses minutes and is more useful when investigating recent system activity.

Modified during the last 24 hours
find /var/log -type f -mtime -1
Modified during the last 30 minutes
find /tmp -type f -mmin -30
Older than 30 days
find /var/log -type f -mtime +30
09

Modification, access and metadata time

-mtime tracks content modification time, -atime tracks access time and -ctime tracks inode metadata changes such as permissions or ownership. ctime is not the file creation time.

Metadata changed recently
find /etc -type f -ctime -1
Accessed recently
find /home -type f -atime -1 2>/dev/null
10

Search newer than another file

-newer compares modification timestamps against a reference file. This is useful when investigating everything changed after a known event.

Files newer than reference file
find /etc -type f -newer /tmp/reference
11

Limit recursion depth

-maxdepth prevents find from descending too deeply. -mindepth can exclude the starting directory itself or shallow results.

Only current directory
find /opt -maxdepth 1 -type f
Maximum two levels
find /var/www -maxdepth 2 -type f
12

Exclude directories with prune

-prune prevents find from descending into matching directories. This is useful for excluding large or irrelevant trees such as proc, sys or node_modules.

Ignore node_modules
find . -path "./node_modules" -prune -o -type f -name "*.js" -print
13

Combine conditions

find supports logical operators. -a means AND, -o means OR and ! negates a condition. AND is implicit when conditions are written consecutively.

PHP or JS files
find /var/www -type f \( -name "*.php" -o -name "*.js" \)
Files excluding logs
find /var/www -type f ! -name "*.log"
14

Execute commands on results

-exec runs another command using each matching path. {} represents the current result. Ending with \; executes once per result, while + groups multiple paths into fewer command executions.

Show detailed permissions
find /opt -type f -exec ls -lh {} \;
Search text inside discovered files
find /etc -type f -name "*.conf" -exec grep -H "password" {} + 2>/dev/null
15

Use -ls and -printf

-ls produces detailed metadata directly from find. -printf allows custom output, making it useful for scripts and investigations.

Detailed listing
find /opt -type f -ls
Custom owner, permissions and path
find /opt -type f -printf '%M %u %g %s %p\n'
16

Useful enumeration searches

Some searches are especially useful during Linux administration and authorised security assessments: privileged binaries, writable configuration files, SSH keys, backups and recently modified files.

Private SSH keys
find /home -type f -name "id_rsa" 2>/dev/null
Backup files
find / -type f \( -name "*.bak" -o -name "*.old" -o -name "*.backup" \) 2>/dev/null
Writable configuration files
find /etc -type f -writable 2>/dev/null