Linux · Systems fluency
How do you find files and content on Linux?
Short answer
find traverses the filesystem with precise predicates, while locate searches a prebuilt index and is much faster but can be stale. Use find when correctness matters and locate for quick exploration.
find evaluates expressions from left to right and can filter by name, type, size, time, owner, and permissions. Actions such as -exec or -delete operate on matches. Quoting patterns prevents the shell from expanding them first.
find /var/log -type f -name "*.log" -mtime +7
find . -type f -size +100M -print
find /srv -type f -name "*.conf" -exec grep -l "listen" {} +Predicates and actions
- -name matches a filename pattern, while -path matches the full path
- -mtime uses days, and -mmin uses minutes
- -type f limits to regular files
- -exec command {} + batches arguments efficiently
- -delete removes matches and should be tested without it first
find will report permission errors unless you redirect stderr or prune inaccessible paths. On a large filesystem, scope the search to the relevant subtree and exclude mounted filesystems with -xdev when appropriate.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What is the difference between find and locate?
- 2Why is -exec {} + usually better than -exec {} semicolon?
- 3How do you exclude another mounted filesystem from a find?
- 4How would you delete files older than 30 days safely?
Say it in the interview
find walks the filesystem and applies predicates, so it is always current but can be slow. locate searches an index and is fast but possibly stale. I scope find to the relevant tree, quote patterns, and use -exec or xargs for actions. For destructive actions I test the match list first.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Linux mock interview and get scored feedback on depth, clarity and confidence.