7 Powerful Ways to Use the Linux find Command (Including Interview Tips)
This article explains seven practical uses of the Linux find command—searching by name, type, timestamps, size, permissions, ownership, and executing actions—provides clear code examples, and shows how to solve a common interview question that deletes files older than one year.
The find command is an essential tool for Linux system administrators and backend developers, frequently appearing in technical interviews. A typical interview question asks how to delete log files in a logs directory that haven’t been accessed for over a year.
Find 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" It is advisable to limit the search to regular files with -type f for clarity:
find ./yang/books -type f -name "*.pdf"Find different file types
Search for directories: find . -type d -name "yang*" Search for symbolic links:
find . -type l -name "yang*"Find by timestamps
atime : last access time.
mtime : last modification time of file contents.
ctime : last change time of file metadata (owner, permissions, etc.).
Find files not accessed for more than 365 days: find . -type f -atime +365 Find files whose modification time is exactly five days ago (no + sign): find . -type f -mtime 5 Find files with change time between 5 and 10 days ago:
find . -type f -ctime +5 -ctime -10Find by size
The -size option lets you specify units: b (512‑byte blocks, default), c (bytes), w (two‑byte words), k (KB), M (MB), G (GB). Use + for “greater than” and - for “less than”. Example: find files between 10 MB and 1 GB:
find . -type f -size +10M -size -1GFind by permissions
Search for files with specific permission bits using -perm: find . -type f -perm 777 This returns files that are readable, writable, and executable by owner, group, and others.
Find by ownership
Use -user to locate files owned by a particular user:
find . -type f -user yangExecute a command on matched files
The -exec action runs a specified command for each file found. For the interview problem, combine the timestamp filter with -exec rm -rf {} to delete old log files: find . -type f -atime +365 -exec rm -rf {} \; Note that {} is a placeholder for each matched file; without it, the command would act on all files in the directory.
Example showing the effect of using or omitting the placeholder:
find . -type f -atime +5 -exec ls {} \; find . -type f -atime +5 -exec ls \;Summary
After learning these seven practical uses of find, the interview question becomes straightforward. The final solution to delete files not accessed for over a year is:
find . -type f -atime +365 -exec rm -rf {} \;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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
