> For the complete documentation index, see [llms.txt](https://cybersecurity-cloud-and-it-notes.gitbook.io/kyles-cybersecurity-cloud-and-it-gitbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cybersecurity-cloud-and-it-notes.gitbook.io/kyles-cybersecurity-cloud-and-it-gitbook/hack-the-box/academy/introduction-to-windows-command-line/finding-files-and-directories.md).

# Finding Files and Directories

Alright! Let's break down the lesson into a fun and ADHD-friendly format! Ready? Let's go!

***

#### **🚀 Fun File and Directory Exploration in CMD!**

You're about to become a master of searching for files and directories using CMD! It's like a treasure hunt, but with a computer. Imagine your computer as a giant library, and you're the librarian with a magical ability to find anything!

#### **🔍 Searching with `where`**

Think of the `where` command like your personal detective 👓. It helps you find files, whether they're hiding or you know exactly where to look.

1. **Find a Program (Like Calculator)**

   ```bash
   C:\Users\student\Desktop>where calc.exe
   ```

   **Result:** This will show you where your **Calculator** is hiding in the system! It’s like going on a scavenger hunt for your favorite tools.

   * **Example:** If you want to find `calc.exe`, you'll see it lives in `C:\Windows\System32\calc.exe`.
2. **When it’s Missing!** If you're looking for something that doesn’t exist, it’s like the treasure chest was never buried! 🌪️

   ```bash
   C:\Users\student\Desktop>where bio.txt
   INFO: Could not find files for the given pattern(s).
   ```
3. **Searching Deep in the Folders with `/R`** Want to go deep inside every folder? Let’s unleash the power of **Recursive Search**! 🕵️‍♀️

   ```bash
   C:\Users\student\Desktop>where /R C:\Users\student\ bio.txt
   ```

   This searches everywhere in `C:\Users\student\`, finding `bio.txt` in the `Downloads` folder. Cool, right?
4. **Searching for Specific Types** Want to find all `.csv` files? Just ask!

   ```bash
   C:\Users\student\Desktop>where /R C:\Users\student\ *.csv
   ```

***

#### **📝 Digging Deeper with `find` and `findstr`**

Now, you can search not just for files, but **inside the files** too! 🎯 Let’s say you’re hunting for a secret word (like "password").

1. **Simple Search with `find`**

   ```bash
   C:\Users\student\Desktop>find "password" "C:\Users\student\not-passwords.txt"
   ```

   This will look for the word **password** inside the file **not-passwords.txt**.
2. **Supercharged Search with `findstr`** Need more power? `findstr` is like `find` on steroids. It can search using **wildcards**, **patterns**, even **regex**! 💪

   ```bash
   C:\Users\student\Desktop>findstr "pattern" file.txt
   ```

***

#### **⚡ Comparing Files: `comp` and `fc`**

What if you have two files and want to compare them, side by side? Let’s say one was changed. **`comp`** and **`fc`** will help you!

1. **The "Byte" Comparison - `comp`** This one compares files **byte by byte** and will show you **where they’re different**! It's like a super-detailed detective. 🧐

   ```bash
   C:\Users\student\Desktop>comp file-1.md file-2.md
   ```

   If there's a difference, like the letter "a" in file-1 vs. "b" in file-2, it’ll show you exactly where!
2. **Line-by-Line Comparison - `fc`** Want a **line-by-line** comparison? `fc` is your guy. It's a bit more specific and even shows **line numbers**!

   ```bash
   C:\Users\student\Desktop>fc passwords.txt modded.txt /N
   ```

   This will show you exactly which lines are different!

***

#### **💡 Sorting with `sort`**

Sometimes, your files might be all jumbled up like socks in a laundry basket. 😱 But with **`sort`**, you can easily arrange them in order!

1. **Simple Sorting**

   ```bash
   C:\Users\student\Desktop>sort file.txt /O sorted-file.txt
   ```

   It takes **file.txt**, sorts it, and then stores it into **sorted-file.txt**.
2. **Unique Sorting (No Duplicates!)** Ever wanted to remove duplicates? You can do that too!

   ```bash
   C:\Users\MTanaka\Desktop>sort.exe file.txt /unique
   ```

   This will give you a clean list with **only unique entries**. It’s like sorting your friends list by the coolest first! 🏆

***

#### **🔑 Key Takeaways for Your Treasure Hunt:**

* **`where`** = Find files and programs on your system!
* **`find`** = Search for **specific strings** inside files!
* **`findstr`** = Next-level search, with patterns and regex!
* **`comp`** = Compare files **byte by byte**.
* **`fc`** = Compare files **line by line**.
* **`sort`** = Sort through files or data, and clean up duplicates!

Now you’re ready to go on your next **file-finding adventure**! 🌟

***

#### 💭 **Quick Question Time:**

* If you want to find a file **inside a specific folder**, what command could you use? 🤔
* What’s the difference between `comp` and `fc`? Can you guess? 😎

***

And there you go! You’ve just mastered the **art of finding and comparing files** in CMD. Ready to take on your next challenge? 🌈
