Skip to main content

Find & Xargs Cheatsheet

find is the most powerful file search tool on Linux, and xargs is its perfect companion for batch processing. This cheatsheet organizes essential find and xargs commands by category — name/path, time, size, type, permission searches, execution, and batch actions — each with practical examples.

Updated: 2026-07-16·33 commands

Quick Reference

TaskCommand
Search by namefind . -name "*.txt"
Find recently modified filesfind . -mtime -7
Find large filesfind . -size +100M
Execute action on resultsfind . -exec rm {} \;
Find only directories or filesfind . -type d
Find by permissionsfind . -perm 644
Batch process resultsfind . -print0 \xargs -0

``bash # Search by name find . -name "*.txt" # Exact filename match find . -iname "readme*" # Case-insensitive find . -name "[ab]*.py" # Glob patterns find . -name "*.tmp" -o -name "*.log" # OR condition (-o)

# Search by path find . -path "*/src/*.c" # Match by path find . -ipath "*/.git/*" # Path case-insensitive find . -regex '.*\.\(txt\|md\)$' # Regex match on full path find . -regextype posix-egrep -regex '.*\.(txt|md)$'

# Negation find . -not -name "*.txt" # Negate result find . ! -name "*.txt" # Shorthand negation (!)

# Limit search depth find . -maxdepth 1 -name "*.txt" # Current directory only find . -mindepth 2 -name "*.txt" # Start from depth 2 find . -maxdepth 3 -mindepth 1 # Depth 1-3

# Search by inode find . -inum 1234567 # Find by inode number find . -samefile /path/to/file # Find hard links `

Time Filters

`bash # Modification time (mtime) find . -mtime -7 # Modified in the last 7 days find . -mtime +30 # Modified more than 30 days ago find . -mtime 0 # Modified today

# Access time (atime) find . -atime -3 # Accessed in the last 3 days

# Status change time (ctime) find . -ctime -1 # Status changed in the last day

# Minute precision find . -mmin -60 # Modified in the last 60 minutes find . -mmin +120 # Modified more than 120 minutes ago

# Newer file comparison find . -newer reference.txt # Files newer than reference.txt find . -anewer reference.txt # Files with newer access time find . -cnewer reference.txt # Files with newer status change

# Combined time conditions find . -mtime -7 -a -mtime +0 # In the last 7 days but not today find . -daystart -mtime -1 # Last 1 day from midnight `

Size Filters

`bash # Exact size find . -size 1024c # Exactly 1024 bytes find . -size 1k # Exactly 1KB (1024 bytes)

# Greater than / Less than find . -size +100M # Greater than 100MB find . -size -1G # Less than 1GB find . -size +500k -a -size -1M # Between 500KB and 1MB

# Units find . -size +1G # Greater than 1GB find . -size +10M # Greater than 10MB find . -size +1000k # Greater than 1000KB find . -size +1M -a -size -10M # Between 1MB and 10MB

# Empty files / directories find . -empty # Empty files or directories find . -type f -empty # Empty files find . -type d -empty # Empty directories `

Execution

`bash # -exec basics find . -name "*.bak" -exec rm {} \; # Delete each file (\; terminates) find . -name "*.log" -exec rm {} + # Batch as args (+ is faster)

# -ok with confirmation find . -name "*.tmp" -ok rm {} \; # Confirm before each deletion

# Multi-step execution find . -name "*.txt" -exec cp {} {}.back \; # Copy with .back suffix

# execdir (execute in file's directory) find . -name "*.txt" -execdir rm {} \; # Safer (runs in file's dir) find . -name "*.jpg" -execdir convert {} {}.png \; # Image conversion

# Complex commands with sh -c find . -name "*.html" -exec sh -c 'gzip "{}"' \; # Per-file execution find . -name "*.log" -exec sh -c 'mv "$1" "${1%.log}.txt"' _ {} \; # Rename

# Delete matching files find . -name "*.swp" -delete # Direct delete (faster than -exec rm) `

Type Filters

`bash # File types find . -type f # Regular files only find . -type d # Directories only find . -type l # Symbolic links only find . -type s # Socket files only find . -type p # Named pipes (FIFO) find . -type b # Block devices find . -type c # Character devices

# Combined types find . -type f -o -type l # Files or symlinks find . -type f -a -name "*.sh" # Regular files ending in .sh

# Links find . -type l -ls # Find symlinks and list details find . -xtype l # Find broken symlinks `

`bash # Exact permission match find . -perm 644 # Exact permission 644 find . -perm 755 # Exact permission 755

# Contains permission find . -perm -u=r # Owner has read permission find . -perm -g=w # Group has write permission find . -perm -o=x # Others have execute permission

# Any user has permission find . -perm /u=r # Any user has read permission find . -perm /222 # Any user has write permission

# Owner / Group find . -user admin # Owned by user admin find . -group www-data # Belongs to group www-data find . -uid 1000 # By user ID find . -gid 100 # By group ID

# Special modes find . -type f -perm /4000 # SUID files find . -type f -perm /2000 # SGID files find . -type f -perm /1000 # Sticky bit `

Batch Operations (Xargs)

`bash # Basic usage find . -name "*.txt" | xargs rm # Delete .txt files (watch for spaces!) find . -name "*.txt" -print0 | xargs -0 rm # Handle spaces in filenames

# Batch operations find . -name "*.py" -print0 | xargs -0 -I {} cp {} /backup/ # Copy to backup find . -name "*.jpg" -print0 | xargs -0 -P 4 convert -resize 50% # Parallel

# Counting and statistics find . -name "*.log" -print0 | xargs -0 wc -l # Count all log lines find . -type f -print0 | xargs -0 ls -lh # View file details

# Limit arguments per invocation find . -print0 | xargs -0 -n 10 ls -lh # Max 10 args per call

# Placeholder substitution find . -name "*.txt" -print0 | xargs -0 -I file cp file /tmp/ # Named placeholder

# Interactive processing find . -name "*.tmp" -print0 | xargs -0 -p rm # Confirm before execution

# Combined with grep find . -name "*.py" -print0 | xargs -0 grep -l "TODO" # Files containing TODO find . -type f -print0 | xargs -0 grep -c "error" | grep -v ":0$" # Files with errors ``

Basic Search(7)

CommandLevel
find . -name
Search files by name (supports glob patterns)
Basic
find . -iname
Search files by name (case-insensitive)
Basic
find . -path / -ipath
Search by path pattern
Intermediate
find . -regex
Match full path with regex
Expert
find . -maxdepth / -mindepth
Limit search directory depth
Intermediate
find . -not / !
Find files that don't match (negation)
Intermediate
find . -o
Combine conditions with OR
Intermediate

Time Filter(4)

CommandLevel
find . -mtime
Filter by modification time (day precision)
Basic
find . -mmin
Filter by modification time (minute precision)
Intermediate
find . -atime / -amin
Filter by access time
Intermediate
find . -newer
Find files newer than a reference file
Intermediate

Size Filter(3)

CommandLevel
find . -size
Filter by file size (supports +/-
Basic
find . -size +100M
Find files larger than 100MB
Basic
find . -empty
Find empty files or directories
Basic

Execution(6)

CommandLevel
find . -exec {} \;
Execute a command on each matching file
Basic
find . -exec {} +
Execute command with batched arguments
Intermediate
find . -ok
Execute command with confirmation prompt
Intermediate
find . -execdir
Execute command in file's directory (safer)
Expert
find . -delete
Delete matching files directly (faster than -exec rm)
Basic
find . -exec sh -c
Execute complex shell commands
Expert

Type Filter(3)

CommandLevel
find . -type f
Find regular files only
Basic
find . -type d
Find directories only
Basic
find . -type l / -xtype l
Find symlinks or broken symlinks
Intermediate

Permission(4)

CommandLevel
find . -perm
Find by exact permissions
Intermediate
find . -perm -mode
Find files that have the specified permission bits
Intermediate
find . -user / -group
Find files by owner or group
Intermediate
find . -perm /4000
Find SUID/SGID/sticky bit files
Expert

Batch Ops (Xargs)(6)

CommandLevel
xargs -0
Xargs with NUL separator (safe for spaces)
Basic
xargs -I {}
Use placeholder for argument substitution
Intermediate
xargs -P N
Execute commands in parallel (N concurrent processes)
Expert
xargs -n N
Pass at most N arguments per invocation
Intermediate
xargs -p
Prompt before executing each command (interactive)
Intermediate
find . -print0 | xargs -0 grep
Batch search file contents
Intermediate

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-16.