Operations 8 min read

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

This article explains eight practical uses of the Linux find command—including searching by name, type, timestamps, size, permissions, ownership, executing actions on matches, and directory name patterns—providing clear examples and code snippets to help administrators efficiently locate and manage files.

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

In Linux administration, the

find

command is essential for locating files and directories based on various criteria.

<code>find . -type f -atime +365 -exec rm -rf {} \;</code>

1. Search by name or regular expression

Example:

<code>find . -name test.txt</code>

Search for all PDF files:

<code>find ./yang/books -name "*.pdf"</code>

Specify file type for clarity:

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

2. Search by file type

Directories:

<code>find . -type d -name "yang*"</code>

Symbolic links:

<code>find . -type l -name "yang*"</code>

3. Search by timestamps

atime – last access time

mtime – last modification time

ctime – last status change time

Find files not accessed for over a year:

<code>find . -type f -atime +365</code>

Find files modified exactly 5 days ago:

<code>find . -type f -mtime 5</code>

Find files whose ctime is between 5 and 10 days ago:

<code>find . -type f -ctime +5 -ctime -10</code>
Timestamp illustration
Timestamp illustration

4. Search by size

Size units: b (512‑byte blocks), c (bytes), w (two‑byte words), k (KB), M (MB), G (GB).

Find files between 10 MB and 1 GB:

<code>find . -type f -size +10M -size -1G</code>

5. Search by permissions

Find files with permission 777:

<code>find . -type f -perm 777</code>

6. Search by ownership

Find files owned by user

yang

:

<code>find -type f -user yang</code>

7. Execute a command on matches

Delete files not accessed for over a year:

<code>find . -type f -atime +365 -exec rm -rf {} \;</code>

The

{}

placeholder represents each found file; the command must end with an escaped semicolon

\;

.

8. Search by directory name

Case‑insensitive search:

<code>find /path/to/search -type d -iname "directory_name"</code>

Find the most recently modified directory:

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

Awk quick reference

Awk processes structured text. Basic syntax:

<code>awk [options] 'pattern { action }' file</code>

Example file

file.txt

:

<code>name,age,sex,salary
Alice,30,女,9000
Bob,25,男,8000
Carol,35,男,7000
Karry,21,女,5000</code>

Print each line:

<code>awk '{ print }' file.txt</code>

Specify field separator:

<code>awk -F ',' '{ print $1, $3 }' file.txt</code>

Filter rows where age > 30:

<code>awk -F ',' '$2 > 30 { print $1 }' file.txt</code>
Linuxshell scriptingfile-searchawkfind
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

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.