Master the Linux ‘find’ Command: 7 Powerful Ways to Locate and Manage Files
This article explains why the Linux find command is essential for backend and system administrators, presents a common interview question, and walks through seven practical uses—including searching by name, type, timestamps, size, permissions, ownership, and executing actions on matched files.
The find command is a must‑know tool for Linux backend and system administrators, and it frequently appears in technical interviews.
If your Linux server has a directory named logs , how would you delete log files that haven’t been accessed for over a year?
First change to the target directory with cd, then run: find . -type f -atime +365 -exec rm -rf {} \; If you’re not familiar with the command, the article introduces seven real‑world uses of find:
1. Find files by name or regular expression
Search by exact name: find . -name test.txt Search for all PDF books using a pattern: find ./yang/books -name "*.pdf" Specify regular files explicitly:
find ./yang/books -type f -name "*.pdf"2. Find files of different types
Search directories: find . -type d -name "yang*" Search symbolic links:
find . -type l -name "yang*"3. Find files by timestamps
Linux tracks three timestamps: atime (last access), mtime (last content modification), and ctime (last metadata change). To find files whose atime is older than one year: find . -type f -atime +365 To find files modified exactly five days ago (without the “+” operator): find . -type f -mtime 5 To locate files whose ctime is between 5 and 10 days ago:
find . -type f -ctime +5 -ctime -104. Find files by size
The -size option accepts units: b (512‑byte blocks), c (bytes), w (two‑byte words), k (kilobytes), M (megabytes), G (gigabytes). “+” means greater than, “-” means less than. Example – find files between 10 MiB and 1 GiB:
find . -type f -size +10M -size -1G5. Find files by permissions
Use -perm to match permission bits. Example – find all files with 777 permissions:
find . -type f -perm 7776. Find files by ownership
Use -user to specify the owning user. Example – find files owned by user yang:
find -type f -user yang7. Execute a command on found files
The -exec action lets you run a command for each matched file. Re‑using the interview question, you can delete the old log files with: find . -type f -atime +365 -exec rm -rf {} \; Here {} is a placeholder for the current file, and the command must end with an escaped semicolon \;. Demonstrating the placeholder effect, compare: find . -type f -atime +5 -exec ls {} \; versus find . -type f -atime +5 -exec ls \; Without the placeholder, the ls runs on all files, not just the matched ones.
After learning these seven uses, the original interview problem becomes straightforward to solve.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
