GO Online Toolset
home
search
To Boss

find command quick check
new
1  |   |   |  0

find Common Commands Cheat Sheet

The find command is used to search for files and directories in a directory hierarchy.

# Search for files by name in current directory and subdirectories (case-sensitive)
find . -name "test.txt"

# Search for files by name (case-insensitive)
find . -iname "test.txt"

# Find all files ending with .log
find . -name "*.log"

# Search using regular expressions
find . -regex ".*\.js"

Search by Type

# Find directories (d: directory)
find . -type d -name "src"

# Find regular files (f: file)
find . -type f -name "*.config"

# Find symbolic links (l: link)
find . -type l

Search by Size

# Find files larger than 100MB
find . -type f -size +100M

# Find files smaller than 10k
find . -type f -size -10k

# Find files exactly 1G in size
find . -type f -size 1G

# Find empty files or directories
find . -empty

Search by Modification Time

# Find files modified in the last 24 hours (n*24 hours)
find . -mtime -1

# Find files modified more than 7 days ago
find . -mtime +7

# Find files modified in the last 10 minutes (minutes)
find . -mmin -10

# Find files accessed in the last 1 hour (atime)
find . -atime -1

# Find files whose status changed in the last 1 hour (ctime, e.g., permission changes)
find . -ctime -1

Search by Permissions and Owner

# Find files with 777 permissions
find . -perm 777

# Find files owned by user root
find . -user root

# Find files belonging to group developers
find . -group developers

Combining Searches (Logical Operators)

# AND (Default): Find directories named code
find . -name "code" -type d

# OR: Find files ending in .sh or .py
find . \( -name "*.sh" -o -name "*.py" \)

# NOT: Find files that do not end with .txt
find . ! -name "*.txt"

Perform Actions After Finding (exec & delete)

# Find and delete all .tmp files (Use with caution)
find . -name "*.tmp" -delete

# Find and list details (execute ls -l for each file found)
find . -name "*.txt" -exec ls -l {} \;

# Find and move to a specific directory
find . -name "*.mp3" -exec mv {} /tmp/music/ \;

# Find and change permissions
find . -type d -exec chmod 755 {} \;

# Find files containing specific content (combine with grep)
find . -type f -name "*.txt" -exec grep -l "search_term" {} +

Depth Control

# Search only in the current directory (don't enter subdirectories)
find . -maxdepth 1 -name "*.js"

# Skip at least two levels of subdirectories
find . -mindepth 3 -name "*.log"