> For the complete documentation index, see [llms.txt](https://42-guide.gitbook.io/42-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://42-guide.gitbook.io/42-guide/piscine-life/shell00/diff.md).

# diff

**Objective:**

The goal of this exercise is to create a file `b` that, when compared to another file `a` using the `diff` command, produces a specific output. This exercise will help you understand how to use the `diff` command to compare files and generate patch files.

**Instructions:**

1. **Create a File Named `b`:**
   * In the `ex07/` directory, create a file named `b`.
   * This file should be created in such a way that when compared to another file `a`, the `diff` command produces a specific output.
2. **Example Scenario:**
   * Suppose file `a` contains the following text:

     ```
     STAR WARS
     Episode IV, A NEW HOPE
     It is a period of civil war.
     Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire.
     During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the DEATH STAR,
     an armored space station with enough power to destroy an entire planet.
     Pursued by the Empire's sinister agents, Princess Leia races home aboard her starship, custodian of the stolen plans that can save her people and restore freedom to the galaxy...
     ```
   * The `diff` command should produce a specific output when comparing `a` and `b`.
3. **Generate the Patch File:**
   * After creating file `b`, run the following command to generate a patch file:

     ```bash
     diff a b > sw.diff
     ```

**Detailed Steps:**

1. **Create the File `b`:**
   * Open your terminal and navigate to the `ex07/` directory.
   * Create a file named `b`:

     ```bash
     touch b
     ```
2. **Edit File `b`:**
   * Open the `b` file in a text editor and modify it so that it differs from file `a` in a specific way. For example, you might change some lines or add/remove text.
3. **Generate the Patch File:**
   * After editing file `b`, run the `diff` command to compare `a` and `b` and generate the patch file:

     ```bash
     diff a b > sw.diff
     ```
4. **Verify the Output:**
   * Check the contents of the `sw.diff` file to ensure it matches the expected output.

**What You Will Learn:**

* **File Comparison:** You will learn how to use the `diff` command to compare two files and identify differences.
* **Patch Files:** You will understand how to generate patch files, which can be used to apply changes from one file to another.
* **Text Manipulation:** You will gain experience in editing and manipulating text files to produce specific outputs.

**Useful Resources:**

* [**Diff Command Documentation**](https://linux.die.net/man/1/diff)**:** Official documentation for the `diff` command.
* [**Patch Command Documentation**](https://linux.die.net/man/1/patch)**:** Official documentation for the `patch` command.
* [**Understanding Diff and Patch**](https://www.digitalocean.com/community/tutorials/how-to-use-diff-and-patch)**:** A tutorial on using `diff` and `patch` commands.
* [**Text File Manipulation**](https://www.gnu.org/software/sed/manual/sed.html)**:** A guide to using `sed` for text file manipulation.

**Conclusion:**

This exercise helps you understand how to use the `diff` command to compare files and generate patch files. By completing this exercise, you will gain practical experience in file comparison and text manipulation, which are essential skills for any developer working with text files and version control systems.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://42-guide.gitbook.io/42-guide/piscine-life/shell00/diff.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
