___________ __________ _____ ________ ________ .____ ___________ \_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/ | __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_ | \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \ \___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ / \/ \/ \/ \/ \/ \/ \/

find Cheatsheet

← Back to cheatsheets

← Home


find searches for files and directories in a directory hierarchy. Powerful tool for locating files by name, type, size, modification time, and more.


Basic Usage

  • find /path -name "pattern" - Find by name
  • find . -type f - Find files only
  • find . -type d - Find directories only
  • find . -name "*.txt" - Find by extension
  • find /path -exec command {} \; - Execute command

Search by Name

  • -name "pattern" - Exact name match
  • -iname "pattern" - Case-insensitive name
  • -path "pattern" - Match path
  • -regex pattern - Regular expression

Search by Type

  • -type f - Files
  • -type d - Directories
  • -type l - Symbolic links
  • -type b - Block devices
  • -type c - Character devices
  • -type p - Named pipes
  • -type s - Sockets

Search by Size

  • -size +100M - Larger than 100MB
  • -size -10k - Smaller than 10KB
  • -size 50c - Exactly 50 bytes
  • -empty - Empty files/directories

Search by Time

  • -mtime -7 - Modified in last 7 days
  • -mtime +30 - Modified more than 30 days ago
  • -atime -1 - Accessed in last 24 hours
  • -ctime -2 - Changed in last 2 days
  • -newer file - Newer than file
  • -amin -60 - Accessed in last 60 minutes
  • -mmin -30 - Modified in last 30 minutes

Search by Permissions

  • -perm 644 - Exact permissions
  • -perm -u+w - User has write
  • -perm /o+x - Others have execute
  • -user username - Owned by user
  • -group groupname - Owned by group

Actions

  • -print - Print results (default)
  • -ls - List like ls -dils
  • -delete - Delete found files
  • -exec command {} \; - Execute command
  • -exec command {} + - Execute with multiple files
  • -ok command {} \; - Interactive exec

Common Examples

Find by Name

find . -name "*.txt"

Find all .txt files.

Find Large Files

find / -size +100M

Find files larger than 100MB.

Find Recent Files

find . -mtime -7

Files modified in last week.

Find and Delete

find . -name "*.tmp" -delete

Delete all .tmp files.

Find and Execute

find . -name "*.sh" -exec chmod +x {} \;

Make scripts executable.

Find Empty Files

find . -type f -empty

Find empty files.

Find by User

find /home -user username

Find files owned by user.

Find Directories

find . -type d -name "config"

Find directories named config.


Tips

  • Use -name for simple patterns
  • Use -iname for case-insensitive
  • Use -type to filter file types
  • Use -size to find large/small files
  • Use -mtime for time-based searches
  • Be careful with -delete
  • Use -exec for batch operations
  • Essential for file system management