DEV Community

Lam
Lam

Posted on

Find Cheat Sheet

Examples

find . -name '*.jpg'
find . -name '*.jpg' -exec rm {} \;
Enter fullscreen mode Exit fullscreen mode
find . -newerBt "24 hours ago"
Enter fullscreen mode Exit fullscreen mode
find . -type f -mtime +29 # find files modified more than 30 days ago
Enter fullscreen mode Exit fullscreen mode

Actions

-exec rm {} \;
-print
-delete
Enter fullscreen mode Exit fullscreen mode

Condition flow

\! -name "*.c"
\( x -or y \)
Enter fullscreen mode Exit fullscreen mode

Access time conditions

-atime 0           # Last accessed between now and 24 hours ago
-atime +0          # Accessed more than 24 hours ago
-atime 1           # Accessed between 24 and 48 hours ago
-atime +1          # Accessed more than 48 hours ago
-atime -1          # Accessed less than 24 hours ago (same a 0)
-ctime -6h30m      # File status changed within the last 6 hours and 30 minutes
-mtime +1w         # Last modified more than 1 week ago
Enter fullscreen mode Exit fullscreen mode

These conditions only work in MacOS and BSD-like systems (no GNU/Linux support).

Conditions

-name "*.c"
Enter fullscreen mode Exit fullscreen mode
-user jonathan
-nouser
Enter fullscreen mode Exit fullscreen mode
-type f            # File
-type d            # Directory
-type l            # Symlink
Enter fullscreen mode Exit fullscreen mode
-depth 2           # At least 3 levels deep
-regex PATTERN
Enter fullscreen mode Exit fullscreen mode
-size 8            # Exactly 8 512-bit blocks 
-size -128c        # Smaller than 128 bytes
-size 1440k        # Exactly 1440KiB
-size +10M         # Larger than 10MiB
-size +2G          # Larger than 2GiB
Enter fullscreen mode Exit fullscreen mode
-newer   file.txt
-newerm  file.txt        # modified newer than file.txt
-newerX  file.txt        # [c]hange, [m]odified, [B]create
-newerXt "1 hour ago"    # [t]imestamp
Enter fullscreen mode Exit fullscreen mode

Usage

{: .-prime}

find <path> <conditions> <actions>
Enter fullscreen mode Exit fullscreen mode

Reference

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay