Skip to content

find

22 commands

Searches the directory tree by name, type, size, time, owner or permissions — and runs actions on matches.

  • search
  • files
  • permissions

Install find

sudo apt install findutils

By name and type5

find <dir> -name "<pattern>"

Finds files whose name matches a glob (case-sensitive).

Link
find <dir> -iname "<pattern>"

Case-insensitive name match; 2>/dev/null hides permission errors.

Link
find <dir> -type f

Files only. Use -type d for directories and -type l for symlinks.

Link
find <dir> -maxdepth <n> -name "<pattern>"

Limits how deep the search goes.

Link
find <dir> -path "<pattern>" -prune -o -name "<name>" -print

Skips a directory tree entirely.

Link

By size and time6

find <dir> -size +<n>

Files larger than a size (k, M, G). Use - for smaller.

Link
find <dir> -empty

Empty files and directories.

Link
find <dir> -mtime -<n>

Modified in the last n days.

Link
find <dir> -mmin -<n>

Modified in the last n minutes — useful when investigating a recent compromise.

Link
find <dir> -newer <file>

Files modified more recently than a reference file.

Link
find <dir> -newermt "<date>"

Files modified between two dates.

Link

By owner and permission6

find / -perm -4000 -type f 2>/dev/null

Lists SUID binaries. Compare against GTFOBins for privilege-escalation paths.

Link
find / -perm -2000 -type f 2>/dev/null

Lists SGID binaries.

Link
find / -writable -type d 2>/dev/null

Directories your current user can write to.

Link
find / -perm -o+w -type f ! -path "/proc/*" 2>/dev/null

World-writable files outside /proc.

Link
find <dir> -user <user>

Files owned by a user.

Link
find / -nouser -o -nogroup 2>/dev/null

Files whose owner or group no longer exists.

Link

Acting on results5

find <dir> -name "<pattern>" -exec <cmd> {} \;

Runs a command on each result.

Link
find <dir> -name "<pattern>" -exec <cmd> {} +

Passes many results to one command invocation — much faster.

Link
find <dir> -name "<pattern>" -delete

Deletes matches. Run without -delete first to check what will go.

Link
find <dir> -type f -print0 | xargs -0 <cmd>

Safely handles names with spaces or newlines.

Link
find <dir> -type f -printf "%T@ %p\n" | sort -n | tail

Lists the most recently modified files (GNU find).

Link