Operations 7 min read

Master the Linux ‘find’ Command: Powerful File Search Techniques

Learn how to use the versatile Unix ‘find’ command to search and manipulate files by name, type, size, timestamps, and more, with detailed syntax, common options, and practical examples for printing, deleting, and executing actions on matched files.

Raymond Ops
Raymond Ops
Raymond Ops
Master the Linux ‘find’ Command: Powerful File Search Techniques

The find command is a powerful tool in Unix and Unix‑like systems (e.g., Linux) for searching files and directories within a directory tree. It offers many options to perform complex searches based on name, type, time, size, etc.

Basic Syntax

find [path] [options] [test] [action]

path : directories to search; can be one or more paths or . for the current directory.

options : control find behavior such as ignoring errors or showing help.

test : criteria to match files, e.g., name, type, modification time.

action : what to do with matched files, e.g., print path, delete.

Common Options

-name

: match files by name. Example:

find /path -name "*.txt"
-iname

: case‑insensitive name match. Example:

find /path -iname "*.jpg"
-type

: match by file type. f for regular file, d for directory, l for symlink. Example:

find /path -type d
-size

: match by file size. Units: c (bytes), k (KB), M (MB). Example:

find /path -size +1M
-mtime

: match by modification time in days. -mtime -7 finds files modified within the last 7 days. -ctime: match by change time of metadata. Example:

find /path -ctime +30
-atime

: match by last access time. Example:

find /path -atime -1
-mmin

: match by modification time in minutes. Example:

find /path -mmin +60
-cmin

: match by metadata change time in minutes. Example:

find /path -cmin -30
-amin

: match by access time in minutes. Example:

find /path -amin +10

Actions

-print

: default action, prints the path of matched files. -exec: execute a command on each matched file. Example:

find /path -name "*.tmp" -exec rm -f {} \;
-delete

: delete matched files (use with caution). -print0: prints paths separated by a null character, useful with xargs -0. -prune: exclude specified directories from the search.

Examples

Find all .log files in the current directory: find . -name "*.log" Find files larger than 100 MB in /var/log: find /var/log -size +100M Delete files modified more than 7 days ago: find /path -mtime +7 -exec rm -f {} \; Print files accessed in the last 30 minutes: find /path -amin -30 -print Find and delete all .tmp files (use carefully):

find /path -name "*.tmp" -delete

Summary

The find command is a versatile utility for locating and operating on files in a directory tree; mastering its options and actions enables efficient file management on Unix/Linux systems.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxUnixFile Searchfind
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.