Master Linux ‘find’: 7 Powerful Uses Every Dev Should Know
This article explains why the Linux find command is essential for developers, walks through a common interview problem of deleting year‑old log files, and details seven practical find usages—including name/regex search, type filtering, timestamps, size, permissions, ownership, and executing commands on matches.
The find command is a must‑know tool for Linux developers and frequently appears in technical interviews; for example, to delete log files in a logs directory that haven’t been accessed in over a year.
cd logs
find . -type f -atime +365 -exec rm -rf {} \;The article then presents seven real‑world find usages.
1. Find by name or regular expression
find . -name test.txt find ./yang/books -name "*.pdf" find ./yang/books -type f -name "*.pdf"2. Find different file types
find . -type d -name "yang*" find . -type l -name "yang*"3. Find by timestamps
Linux tracks three timestamps: atime (last access), ctime (last status change), and mtime (last content modification).
find . -type f -atime +365 find . -type f -mtime 5 find . -type f -ctime +5 -ctime -104. Find by file size
Use -size with units: b (512‑byte blocks), c (bytes), w (2‑byte words), k (KB), M (MB), G (GB).
find . -type f -size +10M -size -1G5. Find by permissions
find . -type f -perm 7776. Find by ownership
find . -type f -user yang7. Execute a command on each match
Use -exec to run actions such as removal or listing; the command must end with an escaped semicolon \; and the placeholder {} represents the current file.
find . -type f -atime +365 -exec rm -rf {} \; find . -type f -atime +5 -exec ls {} \;Note: Omitting the placeholder {} causes the command to act on all files, not just those found.
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.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
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.
