Mastering Linux Find: 8 Powerful Use Cases for System Operations
This article explains why the Linux find command is essential for administrators, walks through a common interview question about deleting year‑old log files, and then presents eight practical find usages—including name patterns, file types, timestamps, size, permissions, ownership, execution actions, and directory searches—complete with ready‑to‑run code examples.
The find command is a must‑know tool for Linux operations and system administration.
Interview question: How to delete log files in a .logs directory that haven’t been accessed for over a year? find . -type f -atime +365 -exec rm -rf {} \; If you’re not comfortable with the command above, this article introduces eight practical find use cases that will help you master it.
1. Find files by name or regular expression
Search for a specific file 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 files of different types
Search for directories: find . -type d -name "yang*" Search for symbolic links:
find . -type l -name "yang*"3. Find files by timestamp
Linux tracks three timestamps:
atime : last access time.
mtime : last modification time.
ctime : last status change time (ownership, permissions, etc.).
Find files with access time older than one year: find . -type f -atime +365 Find files with modification time exactly five days ago (no + sign): find . -type f -mtime 5 Find files with change time between five and ten days ago:
find . -type f -ctime +5 -ctime -104. Find files by size
Use -size with units (b, c, w, k, M, G):
find . -type f -size +10M -size -1G5. Find files by permissions
Search for files with specific permission bits (e.g., 777):
find . -type f -perm 7776. Find files by ownership
Search for files owned by a specific user:
find -type f -user yang7. Execute a command on found files
After locating files, you can run actions such as delete or list them using -exec: find . -type f -atime +5 -exec ls {} \; Note: the command after -exec must end with an escaped semicolon ( \;).
8. Search by directory name
Find directories by name (case‑sensitive):
find /path/to/search -type d -name "directory_name"Case‑insensitive search:
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 -1After reviewing these eight techniques, the original interview question becomes straightforward; you can now provide the exact command and explain each part.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
