Skip to content

find command

Search for files by name, size, age, type or permissions and act on them.

On this page

Syntax

find [path…] [tests] [actions]

Provided by the findutils package. Run man find for the full manual.

Common options

OptionWhat it does
-name PATTERNMatch the file name (case-sensitive)
-iname PATTERNMatch the name, ignoring case
-type fd|l | Files, directories or symlinks
-size +N[kMG]Larger (+) or smaller (-) than N
-mtime NModified N days ago (+N older, -N newer)
-mmin NModified N minutes ago
-user NAMEOwned by a user
-perm MODEMatch permissions, e.g. 777
-maxdepth NDescend at most N levels
-exec CMD {} +Run a command on the results
-deleteDelete what matches

Examples

  1. Find a file by name

    find / -name "nginx.conf" 2>/dev/null
  2. Name, ignoring case

    find . -iname "*.jpg"
  3. Only directories

    find /var/www -type d -name "cache"
  4. Files larger than 100 MB

    find / -type f -size +100M
  5. Files modified in the last 7 days

    find /home -type f -mtime -7
  6. Delete files older than 30 days

    find /backups -type f -mtime +30 -delete
  7. Files with 777 permissions

    find /var/www -type f -perm 0777
  8. Files owned by a user

    find / -user www-data -type f
  9. Run a command on each result

    find . -name "*.sh" -exec chmod +x {} +
  10. Exclude a directory

    find . -path ./node_modules -prune -o -name "*.js" -print
  11. Limit the depth

    find /etc -maxdepth 1 -name "*.conf"
  12. Empty files and directories

    find . -empty

Tips

  • Quote patterns like "*.log" so the shell doesn't expand them first.
  • Test with -print before you switch to -delete.

find guides

See all 12 guides that use find →

← All Linux commands · Suggest a fix

Back to top