> For the complete documentation index, see [llms.txt](https://docs.slingdata.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.slingdata.io/concepts/hooks/delete.md).

# Delete

Delete hooks allow you to remove files or directories from local or remote storage locations. This is useful for cleanup operations, removing temporary files, or maintaining storage quotas.

## Configuration

```yaml
- type: delete
  location: "aws_s3/path/to/file"   # Required: Location string
  recursive: false        # Optional: true/false. Default is false
  on_failure: abort       # Optional: abort/warn/quiet/skip
  id: my_id               # Optional. Will be generated. Use `log` hook with {runtime_state} to view state.
```

## Properties

| Property    | Required | Description                                                                                          |
| ----------- | -------- | ---------------------------------------------------------------------------------------------------- |
| location    | Yes      | The [location](/sling-cli/environment.md#location-string) string. Contains connection name and path. |
| recursive   | No       | Whether to delete recursively                                                                        |
| path        | Yes      | The path to the file or directory to delete                                                          |
| on\_failure | No       | What to do if the deletion fails (abort/warn/quiet/skip)                                             |

## Output

When the delete hook executes successfully, it returns the following output that can be accessed in subsequent hooks:

```yaml
status: success  # Status of the hook execution
path: "path/to/file"  # The path that was deleted
```

You can access these values in subsequent hooks using the following syntax (`jmespath`):

* `{state.hook_id.status}` - Status of the hook execution
* `{state.hook_id.path}` - The path that was deleted

## Examples

### Clean Up Temporary Files

Remove temporary files after successful processing:

```yaml
hooks:
  post:
    - type: delete
      location: "local//tmp/processed/{run.stream.name}_{timestamp.date}/*"
      on_failure: warn
```

### Clean Up Staging Area

Remove processed files from a staging area after successful replication:

```yaml
hooks:
  post:
    - type: delete
      if: run.status == "success"
      location: "azure_blob/staging/{target.environment}/{run.stream.name}/"
      recursive: true
      on_failure: warn
```

### Remove Failed Processing Artifacts

Clean up artifacts from failed processing attempts:

```yaml
hooks:
  post:
    - type: delete
      if: run.status == "error"
      location: "gcs/failed-jobs/{timestamp.date}/{run.stream.name}/"
      on_failure: quiet
```

### Clean Up Log Files

Remove old log files after successful processing:

```yaml
hooks:
  post:
    - type: delete
      location: "local//var/log/sling/{run.stream.name}/*.log"
      on_failure: quiet
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.slingdata.io/concepts/hooks/delete.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
