Operations 10 min read

Comprehensive Guide to Using the Linux find Command for File Search and Management

This article provides a detailed tutorial on the Linux find command, covering how to locate files by name, type, size, time, and permissions, combine conditions, execute actions, and compare it with the locate utility, offering practical examples for system administrators.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Comprehensive Guide to Using the Linux find Command for File Search and Management

The find command is one of the most powerful tools in Linux for searching files based on various attributes such as name, size, permissions, owner, modification time, and access time.

Case studies demonstrate practical usage:

1. Search by file name

$ find . -name "*.go"
$ find /etc -name "[A-Z]*.txt" -print
$ find . -name "out*" -prune -o -name "*.txt" -print
$ find . -path "./git" -prune -o -name "*.txt" -print
$ find . -num 138956

2. Search by file type

$ find . -type l -print
$ find . -type f -name "*.log"

3. Search by file size

$ find . -size -64k -print
$ find . -size +200M -type f -print

4. Search by time

$ find . -mtime -2 -type f -print
$ find . -mtime +2 -type f -print
$ find . -atime -1 -type f -print
$ find . -ctime -1 -type f -print
$ find . -newer "chopin.txt" -type f -print
$ find . ! -newer "chopin.txt" -type f -print

5. Search by permissions

$ find . -type f -perm 644
$ find /etc -type f -perm /222
$ find /etc -perm -111 -ls

6. Combine conditions

$ find . -type f -a -user chopin -print
$ find . -size +2M -o -mtime +2 -print
$ find . -not -type f
$ find . ! -empty

7. Action options

After locating files, find can perform actions such as:

-print (default, prints the path)

-ls (outputs in ls long format)

-delete (removes matched files)

-exec (passes files to any command, e.g., ls -lh {} )

-ok (like -exec but asks for confirmation)

$ find . -name "*.txt" -exec ls -lh {} \;
$ find . -size +100M -delete

8. locate utility

For faster searches, locate uses an indexed database:

$ locate file.txt
$ locate /etc/httpd

Remember to run updatedb to refresh the index for newly created files.

Warning: Scanning large directories (especially / ) can heavily load the CPU; avoid running extensive find queries on production systems without assessing impact.

linuxCommand-lineSystem Administrationfile-searchfind
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

login 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.