> 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/clean.md).

# clean

**Objective:**

The goal of this exercise is to create a command that searches for and deletes specific types of files in the current directory and its subdirectories. The files to be deleted are those with names ending in `~` (backup files) or names that start and end with `#` (temporary files). This exercise will help you understand how to use the `find` command to locate and manage files.

**Instructions:**

1. **Create a File Named `clean`:**
   * In the `ex08/` directory, create a file named `clean`.
   * This file should contain a command that searches for and deletes files with names ending in `~` or names that start and end with `#`.
2. **Command Requirements:**
   * The command should search the current directory and all its subdirectories.
   * The command should delete the files it finds.
   * Only one command is allowed; you cannot use multiple commands separated by `;`, `&&`, or other operators.
3. **Example:**
   * If your directory contains the following files:

     ```
     file1.txt~
     #file2#
     dir1/file3.txt~
     dir1/#file4#
     ```
   * The command should delete all these files.

**Detailed Steps:**

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

     ```bash
     touch clean
     ```
2. **Write the Command:**
   * Open the `clean` file in a text editor and add the following command:

     ```bash
     find . \( -name "*~" -o -name "#*#" \) -delete
     ```
   * This command does the following:
     * `find .`: Starts searching from the current directory (`.`).
     * `\( -name "*~" -o -name "#*#" \)`: Searches for files with names ending in `~` or names that start and end with `#`.
     * `-delete`: Deletes the files that match the search criteria.
3. **Make the File Executable:**
   * After saving the file, make it executable by running:

     ```bash
     chmod +x clean
     ```
4. **Test the Command:**
   * Run the `clean` command to see if it deletes the specified files:

     ```
     ./clean
     ```

**What You Will Learn:**

* **File Searching:** You will learn how to use the `find` command to search for files based on specific criteria.
* **File Deletion:** You will understand how to delete files using the `find` command.
* **Command Efficiency:** You will gain experience in writing efficient commands that perform multiple tasks in a single line.

**Useful Resources:**

* [**Find Command Documentation**](https://linux.die.net/man/1/find)**:** Official documentation for the `find` command.
* [**File Management in Linux**](https://www.digitalocean.com/community/tutorials/basic-linux-commands-for-file-management)**:** A tutorial on basic Linux commands for file management.
* [**Advanced Find Command Usage**](https://www.tecmint.com/35-practical-examples-of-linux-find-command/)**:** Practical examples of using the `find` command.

**Conclusion:**

This exercise helps you understand how to use the `find` command to search for and delete specific types of files. By completing this exercise, you will gain practical experience in file management and command-line efficiency, which are essential skills for any developer working in a Unix-like environment.


---

# 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/clean.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.
