Skip to main content

Linux find Command Guide: Search Files by Name, Size, and Time

·476 words·3 mins
Linux Command Line System Administration File Management
Table of Contents

Linux find Command Guide: Search Files by Name, Size, and Time

The find command is one of the most powerful tools in Linux and Unix-like systems for locating files and directories.

Unlike simple search tools, find supports advanced filtering based on attributes like name, size, type, permissions, and timestampsβ€”making it essential for system administration and automation.


πŸ” Basic Syntax and Structure
#

The general syntax of the find command is:

find [path] [expression]
  • Path Starting directory (e.g., . for current directory, /home/user for absolute path)

  • Expression Defines search conditions using tests, options, and actions

Expressions can be combined using logical operators:

  • -and (default)
  • -or
  • -not

πŸ“„ Search Files by Name
#

Exact Match
#

find . -name "abc.zip"

Searches for files named exactly abc.zip in the current directory and subdirectories.


Case-Insensitive Search #

find . -iname "abc.zip"

Matches variations like ABC.zip, Abc.zip, etc.


πŸ“ Limit Search Depth
#

To restrict how deep find searches into subdirectories:

find . -maxdepth 1 -name "abc.zip"
  • -maxdepth 1 limits the search to the current directory only

This is useful for improving performance and avoiding unnecessary recursion.


⏱️ Search by Time and File Type
#

Modification Time (-mtime)
#

  • Modified within the last 7 days:
find . -name "abc.zip" -mtime -7
  • Modified more than 7 days ago:
find . -name "abc.zip" -mtime +7

File Type (-type)
#

  • Regular files:
find . -type f -name "abc.zip"
  • Directories:
find . -type d -name "abc"

βš™οΈ Combine Conditions for Advanced Queries
#

You can chain multiple filters to refine results.

Example: Find Large Recent Files
#

find . -name "*.zip" -size +100k -mtime -30

This finds:

  • .zip files
  • Larger than 100 KB
  • Modified within the last 30 days

Size Filters:
#

  • -size +100k β†’ Larger than 100 KB
  • -size -10M β†’ Smaller than 10 MB

🧩 Execute Actions on Results
#

The -exec option allows you to run commands on matched files.

Delete Matching Files (Use Carefully)
#

find . -name "abc.zip" -exec rm {} \;
  • {} represents each matched file
  • \; terminates the command

Save Results to a File
#

find . -name "abc.zip" > found_files.txt

Redirects output to a text file for later use.


🌐 Search the Entire System
#

To search from the root directory:

sudo find / -name "abc.zip"
  • Requires sudo to access restricted directories
  • May take longer depending on system size

πŸ“Š Common Expressions Reference
#

Expression Description
-name Match filename (case-sensitive)
-iname Match filename (case-insensitive)
-type f / d Filter by file or directory
-mtime Filter by modification time (days)
-size Filter by file size (k, M, G)
-exec Execute command on results

βœ… Summary
#

The find command is a versatile and essential tool for:

  • Locating files quickly
  • Performing advanced filtered searches
  • Automating file operations

By combining conditions like name, size, and time, you can build powerful queries that significantly improve productivity in the Linux command line.

Related

Linux netstat Command Guide: Check Ports, Connections, and Stats
·391 words·2 mins
Linux Networking System Administration Command Line
Linux Pipes Explained: Practical Examples for Everyday Use
·547 words·3 mins
Linux Command Line Shell
Essential Commands to View and Analyze Linux Log Files
·459 words·3 mins
Linux Logs System Administration