Catalog / Find Command Cheat Sheet
Find Command Cheat Sheet
A concise cheat sheet for the `find` command, covering essential options, conditions, and actions for locating files and directories in Unix-like operating systems. Includes practical examples for common use cases.
Basic Usage and Conditions
Basic Syntax
Searches for files and directories based on specified criteria, starting from a given path. |
Path: The directory to start the search in (e.g., |
Name-Based Conditions
|
Matches filenames exactly as specified by the pattern. Example: |
|
Case-insensitive version of Example: |
User/Group Conditions
|
Finds files owned by the specified username. Example: |
|
Finds files belonging to the specified group. Example: |
|
Finds files that are not owned by a valid user (orphaned files). Example: |
|
Finds files that do not belong to a valid group. Example: |
Type-Based Conditions
|
Finds regular files. Example: |
|
Finds directories. Example: |
|
Finds symbolic links. Example: |
|
Finds block special files. Example: |
|
Finds character special files. Example: |
|
Finds named pipes (FIFOs). Example: |
|
Finds sockets. Example: |
Size and Time Conditions
Size-Based Conditions
|
Finds files of the specified size.
|
|
Finds files larger than 10MB. Example: |
|
Finds files smaller than 10KB. Example: |
|
Finds files exactly 1GB in size. Example: |
Time-Based Conditions
|
Finds files last accessed Example: |
|
Finds files last modified Example: |
|
Finds files whose status was last changed Example: |
|
Finds files modified more recently than Example: |
|
Finds files which were accessed more recently than Example: |
|
Finds files which had their status changed more recently than Example: |
Newer With Time
|
Finds files modified more recently than the timestamp. Example: |
|
Finds files which were accessed more recently than the timestamp. Example: |
|
Finds files which had their status changed more recently than the timestamp. Example: |
Actions and Advanced Options
Action-Based Options
|
Prints the matched file or directory path to standard output (default action). Example: |
|
Executes the specified command on each matched file. Example: |
|
Similar to Example: |
|
Deletes the matched files or directories (use with caution!). Example: |
Combining Conditions
|
Finds files that satisfy both Example: |
|
Finds files that satisfy either Example: |
|
Finds files that do not satisfy the specified condition. Example: |
Other Useful Options
|
Processes the contents of each directory at the specified level. Useful for controlling search depth. Example: |
|
Descends at most Example: |
|
Does not apply any tests or actions at levels less than Example: |
|
Uses a regular expression to match the entire file path. Example: |
Practical Examples
Common Use Cases
Finding and deleting empty directories: |
Finding files modified in the last hour: |
Finding setuid files: |
Finding files without execute permissions for others: |
Finding files that have been accessed in the last week: |
Finding files owned by a specific user and group: |
Advanced Examples
Finding and compressing files older than 30 days: |
Listing all files in the current directory sorted by size: |
Finding all files bigger than 10MB and prompting before deleting: |
Executing a script on each found file: |
Handling Errors
Suppressing error messages (e.g., permission denied): |
Logging errors to a file: |