Operations 8 min read

Master Linux Find: 8 Powerful Ways to Locate and Manage Files

This article explains why the Linux find command is essential for operations, walks through an interview question about deleting year‑old logs, and then details eight practical find usages—including name patterns, file types, timestamps, sizes, permissions, ownership, executing actions, and directory searches—complete with example commands.

Efficient Ops
Efficient Ops
Efficient Ops
Master Linux Find: 8 Powerful Ways to Locate and Manage Files

It can be said with confidence that the find command is one of the essential operations every Linux operator must know.

If your Linux server has a directory named .logs , how would you delete log files whose last access time is more than one year ago?

The answer is to change to the directory and run: find . -type f -atime +365 -exec rm -rf {} \; The article then introduces eight practical uses of the find command.

1. Find files by name or regular expression

Search by a specific name: find . -name test.txt Search for all PDF books using a pattern: find ./yang/books -name "*.pdf" Specify the file type for clarity:

find ./yang/books -type f -name "*.pdf"

2. Find different types of files

Search for directories: find . -type d -name "yang*" Search for symbolic links:

find . -type l -name "yang*"

3. Find files by timestamps

Linux tracks three timestamps:

Access time ( atime): last time the file was read.

Modification time ( mtime): last time the file content changed.

Change time ( ctime): last time metadata (owner, permissions, etc.) changed.

To find files with an access time older than a year: find . -type f -atime +365 To find files whose modification time is exactly five days ago (no + sign): find . -type f -mtime 5 To find files with a change time between 5 and 10 days ago:

find . -type f -ctime +5 -ctime -10

4. Find files by size

The -size option accepts the following units:

b – 512‑byte blocks (default)

c – bytes

w – two‑byte words

k – kilobytes

M – megabytes

G – gigabytes

Example: find files between 10 MB and 1 GB:

find . -type f -size +10M -size -1G

5. Find files by permissions

Use -perm to match specific permission bits, e.g., files with 777 permissions:

find . -type f -perm 777

6. Find files by ownership

Search for files owned by a specific user with -user:

find -type f -user yang

7. Execute a command on found files

After locating files, you can run a command on each of them using -exec. For the interview question: find . -type f -atime +365 -exec rm -rf {} \; Note that the placeholder {} represents each found file; omitting it would apply the command to all files.

8. Search by directory name

Find directories by name (case‑insensitive):

find /path/to/search -type d -iname "directory_name"

Find the most recently modified directory:

find /path/to/search -type d -printf '%T+ %p
' | sort -n | tail -1

Summary

Besides find, Linux also offers commands like grep, locate, which, and fd for file discovery.

After reviewing the eight usages above, the interview question becomes straightforward; the answer is:

find . -type f -atime +365 -exec rm -rf {} \;
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.

LinuxFile Searchfind command
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

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.