DEV Community

Cover image for File Searching Like a Pro: find, locate and which
Sana Muhammad Sadiq
Sana Muhammad Sadiq

Posted on

File Searching Like a Pro: find, locate and which

Introduction

As I continue my RHCSA journey with the 30-day Linux challenge. Today’s focus is one of those everyday essentials that saves time, boosts efficiency and solves the age-old question: "Where did that file go?"

Let’s talk about file searching in Linux using the powerful trio: find, locate and which.

Index

  1. What Are These Commands
  2. Real Life Use Cases
  3. Pro Tips
  4. Industrial Insight
  5. Quick Summary

🔍 What Are These Commands?

1. find

A versatile and powerful command to search for files and directories in real time.

find /home/sana -name "report.txt"
Enter fullscreen mode Exit fullscreen mode

This searches for a file named report.txt starting from /home/sana.

2. locate

Faster than find because it searches through a prebuilt database.

locate report.txt
Enter fullscreen mode Exit fullscreen mode

Bonus tip: Update the database with sudo updatedb before using.

3. which

Used to locate the executable path of a command.

which python3
Enter fullscreen mode Exit fullscreen mode

It tells you where python3 is installed on your system.

💡 Real Life Use Cases

  • Sysadmin Troubleshooting – Find misplaced logs or config files in seconds.
  • Development Setup – Locate compilers, interpreters or toolchains installed.
  • Audits & Backups – Combine find with mtime to identify old files for cleanup or backup.

🚀 Pro Tips

  • Search files by modification time:
  find . -mtime -2
Enter fullscreen mode Exit fullscreen mode

(Finds files modified in the last 2 days)

  • Combine find with exec:
  find . -type f -name "*.log" -exec rm {} \;
Enter fullscreen mode Exit fullscreen mode

(Deletes all .log files from the current directory down)

  • Want blazing fast results? Use locate but make sure to run updatedb first.

🛠️ Industrial Insight

In production environments, time matters.
Searching for the right config file or script quickly can reduce downtime.
Advanced users often combine these tools in automation scripts for health checks or audits.

✅ Quick Summary

Command Best For
find Deep, real-time file searches with powerful filters
locate Super-fast searches with a prebuilt index
which Finding executables in your system path

Mastering these tools means you’ll never lose track of a file again.

Image description

I'd love to hear your thoughts, insights or experiences with Linux. Feel free to share and join the conversation [ Connect with me on LinkedIn www.linkedin.com/in/techwithsana ]💜

#30dayslinuxchallenge #redhat #networking #cloudcomputing #cloudengineer #cloudarchitect #cloud #RHCSA #RHCE #RHEL #WomeninTech #Technology

Top comments (0)