Code & computing / QUICK REFERENCE

GNU find: File, Path, Time and Size Filters

Forty original read-only GNU find examples for names, depth, size, modification time, links, permissions, pruning, and safe filename output.

40 entries

Select by basename, path and depth

Match Python basenames
find sample/ -type f -name '*.py' -print

The quoted glob matches basenames, not directory names; -type f keeps regular files only. Quoting prevents premature shell expansion. [1]

Case-insensitive JPEG extension
find sample/ -type f -iname '*.jpg' -print

GNU -iname ignores case while -name does not. Both .jpg and .JPG can match; this is filename matching, not image-format inspection. [1]

Find a basename in several directories
find sample/ -type f -name 'notes.txt' -print

-name compares only the final path component and may return several files under different parents. [1]

Locate directory basenames
find sample/ -type d -name 'cache' -print

-type d selects directory entries; it does not search file contents or prevent traversal into those directories. [1]

Match file paths beneath a cache directory
find sample/ -type f -path '*/cache/*' -print

-path sees the entire pathname, including directory components; the quoted glob can match both shallow and nested cache files. [1]

Top-level regular files only
find sample/ -maxdepth 1 -type f -print

The starting directory is depth zero; depth one reaches its immediate children. Recursive descendants are not visited. [2]

Exactly two path components beneath root
find sample/ -mindepth 2 -maxdepth 2 -type f -print

Combine minimum and maximum depth to select regular files exactly two levels below sample/. Minimum depth alone still traverses shallower entries. [2]

Match Markdown basenames
find sample/ -type f -name '*.md' -print

Quote '*.md' to pass the wildcard to find rather than letting the calling shell expand it in the current directory. [1]

Regex compares a full pathname
find sample/ -type f -regex '.*[.]py' -print

GNU -regex matches the whole path, not merely the basename; this Emacs-style pattern allows any path prefix ending in .py. [1]

Choose explicit extended regex syntax
find sample/ -regextype posix-extended -type f -regex '.*[.](py|md)' -print

Set the regex dialect before -regex. An unanchored-looking pattern still has to match the entire pathname. [1]

Measure size and modification time

Larger than 1,024 actual bytes
find sample/ -type f -size +1024c -print

With the c suffix, -size measures bytes; +1024 means strictly greater than 1,024 bytes. Without c, find rounds in its default 512-byte blocks. [1]

Exactly zero-byte regular files
find sample/ -type f -size 0c -print

The byte unit c makes zero exact. A size test does not imply a file is safe to remove. [1]

Find empty regular files
find sample/ -type f -empty -print

-empty tests emptiness; -type f prevents empty directories from also appearing. [1]

Modified at least eight full days ago
find sample/logs/ -type f -mtime +7 -print

GNU -mtime counts completed 24-hour periods, rounded down. +7 requires more than seven completed periods, i.e. at least eight; it does not mean merely older than exactly 168 hours. [3]

Modified less than one completed day ago
find sample/logs/ -type f -mtime -1 -print

The -1 threshold selects age with zero completed 24-hour periods; it is relative to when the command runs, not midnight. [3]

Modified within the last sixty minutes
find sample/logs/ -type f -mmin -60 -print

This relative age range uses minutes. The result changes over time and is not a permanently reproducible log query. [3]

Strictly newer than a reference file
find sample/docs/ -type f -newer sample/ref.time -print

-newer compares modification timestamps; equality is not considered newer. The reference file must exist when find parses the expression. [4]

Modified after a UTC cutoff
find sample/docs/ -type f -newermt '2026-10-20 00:00:00 UTC' -print

GNU -newermt parses a time expression and compares file modification time strictly after that instant; explicit UTC avoids machine-local ambiguity. [4]

At or before a UTC cutoff
find sample/docs/ -type f ! -newermt '2026-10-20 00:00:00 UTC' -print

Negating a strict newer-than comparison includes files at or before the cutoff. It is not an atime or creation-time test. [4]

Smaller than 1,024 bytes at the root
find sample/ -maxdepth 1 -type f -size -1024c -print

The -1024c condition is strictly smaller than 1,024 bytes and maxdepth limits the scanned tree. [1]

Inspect types, permissions and readable output

Show every directory entry
find sample/ -type d -print

Directories, including the starting path, are selected; order is traversal-defined rather than guaranteed sorted. [1]

Show symbolic links without following
find sample/ -type l -print

By default GNU find uses -P and tests symlink objects themselves, not the target's file type. [1]

Find files with multiple hard links
find sample/ -type f -links +1 -print

-links counts hard links to the same inode. A separate matching pathname need not indicate a duplicate independent data copy. [1]

Any executable permission bit
find sample/ -type f -perm /111 -print

The / mode prefix tests whether ANY listed execute bit is present; it is not an execution policy or a guarantee the file can run. [1]

Owner-read permission bit set
find sample/ -type f -perm -u=r -print

The - mode prefix tests that all specified bits are set (here, only owner-read). It does not prove the calling user can open the file. [1]

NUL-delimited filename output
find sample/ -type f -name '*.txt' -print0

NUL terminators are robust when names contain spaces, tabs, or newlines. Redirect or pipe only to tools that understand NUL-separated records. [5]

Print only basename of Python files
find sample/code/ -type f -name '*.py' -printf '%f\n'

GNU -printf %f removes path components. A newline-separated listing is human-readable but not safe to parse for arbitrary filenames. [1]

Show target text of each symlink
find sample/ -type l -printf '%p -> %l\n'

%l prints the stored symlink target, not whether the target exists or is trusted. Neither entry is automatically followed. [1]

Remove the starting path prefix
find sample/ -type f -name '*.py' -printf '%P\n'

%P is the path relative to sample/. The directory hierarchy remains visible, unlike %f. [1]

Display byte size next to a Python filename
find sample/code/ -type f -name '*.py' -printf '%s %f\n'

%s is size in bytes and %f is the basename. GNU -printf does not imply output is sorted or safe for arbitrary newline filenames. [1]

Use grouped logic, pruning and bounded traversal

Prune every cache subtree
find sample/ -path '*/cache' -prune -o -type f -name '*.py' -print

When cache matches, -prune prevents descent and the -o right branch does not execute. A mere ! -path test would still traverse caches. [2]

Group alternative suffixes
find sample/ -type f \( -name '*.py' -o -name '*.md' \) -print

Escaped parentheses group OR inside the regular-file test. Without grouping, -o precedence can select unintended items. [1]

Exclude temporary suffixes from output
find sample/ -type f ! -name '*.tmp' -print

Logical NOT filters printed matches. It does not prune directories or remove any files. [1]

Stop at the first matching text file
find sample/ -type f -name '*.txt' -print -quit

-quit terminates traversal immediately after the first printed match. The particular first match depends on traversal order; this is not a sorted result. [2]

Inspect only the root entry
find sample/ -maxdepth 0 -print

Depth zero is the specified starting point itself; no descendants are visited. [2]

List immediate child names without root
find sample/ -mindepth 1 -maxdepth 1 -print

The depth bounds omit the starting point and show its direct children, including directories and symlinks. [2]

Combine Python and text basenames
find sample/ -type f \( -name '*.py' -o -name '*.txt' \) -print

Group both suffix conditions under -type f, because implicit AND binds more tightly than OR. [1]

Filter Python paths without pruning
find sample/ -type f -name '*.py' ! -path '*/cache/*' -print

This prevents printing cached Python paths but still walks those cache trees. Prefer -prune when avoiding traversal is the goal. [2]

Preview temporary-file candidates
find sample/ -type f -name '*.tmp' -print

This is a pure listing. Do not append -delete or execute removals against an unknown source tree. [1]

Bound a recursive listing to depths 1–3
find sample/ -mindepth 1 -maxdepth 3 -type f -print

Both depth options affect traversal/selection. The starting path at depth zero is excluded from matches. [2]

Reserved placement, separate from reference controls. No ad network is active.

Updated Native GNU findutils 4.10.0 on CheatSheetAtlas VPS; primary GNU findutils 4.10 manual checked 26-Oct-2026

Sources

  1. GNU Findutils — full official manual (finding files, tests and output) ↗
  2. GNU Findutils — directories, max/min depth, -prune and -quit ↗
  3. GNU Findutils — age ranges and 24-hour rounding ↗
  4. GNU Findutils — comparing timestamps ↗
  5. GNU Findutils — safe handling of filenames with whitespace and newlines ↗