> 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/google-cybersecurity-professional-cert/4.-linux-and-sql-tool-of-the-trade/module-3/manage-file-content-in-bash/manage-directories-and-files.md).

# Manage directories and files

Let’s turn this lesson into a fun, ADHD-friendly adventure!

***

#### 🏗️ **Building Your Directory and File Empire:**

Think of **directories** and **files** as the building blocks of your Linux world! You’re creating a tiny city where everything has its place, and each piece serves a purpose.

***

#### 🌳 **Growing Your Directory Tree (mkdir & rmdir)**

* **mkdir**: This command is like planting a new tree 🌳! You can create directories (folders) wherever you want.
  * 🛠️ Example: `mkdir network` creates a folder called **network**.
* **rmdir**: Imagine cutting down a tree that’s no longer needed. **rmdir** removes an empty directory.
  * 🛠️ Example: `rmdir network` will remove the **network** directory—just make sure it’s empty!

**Pro Tip:** Use `ls` to double-check that your directories were created or deleted.

***

#### 🗂️ **Creating & Deleting Files (touch & rm)**

* **touch**: This command creates new, empty files. Think of it as placing blank papers into your folders for future reports!
  * 🛠️ Example: `touch permissions.txt` creates a file named **permissions.txt**.
* **rm**: The destroyer 💥. **rm** removes files, so use this with caution!
  * 🛠️ Example: `rm permissions.txt` will delete **permissions.txt** for good.

**Pro Tip:** Run `ls` to confirm your files were created or removed.

***

#### 📦 **Moving & Copying Files (mv & cp)**

* **mv**: Like packing up and moving to a new apartment. **mv** moves files to a new location (or renames them)!
  * 🛠️ Example: `mv permissions.txt logs/` moves **permissions.txt** into the **logs** folder.
  * 🛠️ Example 2: `mv permissions.txt perm.txt` renames **permissions.txt** to **perm.txt**.
* **cp**: This is your **copy-paste** command! **cp** copies files without moving the original.
  * 🛠️ Example: `cp permissions.txt logs/` copies **permissions.txt** into **logs**, but it stays in the original location too.

***

#### ✏️ **Using the Nano Text Editor**

* **nano**: Meet your tiny text editor, **nano**! It’s simple, beginner-friendly, and great for writing/editing files.
  * 🛠️ Example: `nano permissions.txt` opens the file **permissions.txt** in nano for editing.
* **To Save in Nano**: Hit **Ctrl + O**, then press **Enter**. To exit, press **Ctrl + X**.

Now you can write reports or notes directly in Linux!

***

#### 🎯 **Bonus Tool: Redirection ( > & >> )**

* **> and >>**: These are magical arrows that let you send the output of commands directly to a file. Think of them as text teleporters! 📤
  * 🛠️ **>**: Overwrites the file with new content.
    * Example: `echo "Time" > permissions.txt` will replace all the text in **permissions.txt** with “Time”.
  * 🛠️ **>>**: Adds new content to the end of the file (without deleting what’s already there).
    * Example: `echo "Last updated date" >> permissions.txt` will add the string “Last updated date” at the end of the file.

**Pro Tip**: The `>` and `>>` commands will create a new file if the one you’re trying to write to doesn’t exist yet.

***

#### 🏆 **Key Takeaways:**

* Master commands like **mkdir, rmdir, touch, rm, mv, cp** to organize your Linux world.
* Use **nano** to write and edit files directly in your terminal.
* Use **>** and **>>** to direct command output to files—overwriting or appending text.

You’re now ready to manage directories and files like a pro! 🌟 Happy file adventuring!
