---
title: nextflow clean
description: Reference for the nextflow clean command. Clean up cache and work directories.
---

# `nextflow clean`

Clean up *cache* and *work* directories.

## Usage

```console
$ nextflow clean [run_name|session_id] [options]
```

## Description

When you run `nextflow` in a directory, it creates a project-specific `.nextflow.log` file, a `.nextflow` cache directory, and a `work` directory. The `clean` command removes these files from previous runs. Run `nextflow log -q` to list the available run names and session IDs.

If you do not provide a run name or session ID, `clean` removes the files for the latest run.

## Options

##### `-after`

Clean up runs executed *after* the specified one.

##### `-before`

Clean up runs executed *before* the specified one.

##### `-but`

Clean up all runs *except* the specified one.

##### `-n, -dry-run`

Print names of files to be removed without deleting them.

##### `-f, -force`

Force the clean operation.

##### `-h, -help`

Print the command usage.

##### `-k, -keep-logs`

Remove only temporary files, retaining execution log entries and metadata.

##### `-q, -quiet`

Do not print names of files removed.

## Examples

Dry run to remove work directories for the run name `boring_euler`:

```console
$ nextflow clean boring_euler -n

Would remove work/92/c1a9cd9a96e0531d81ca69f5dc3bb7
Would remove work/3f/70944c7a549b6221e1ccc7b4b21b62
Would remove work/0e/2ebdba85f76f6068b21a1bcbf10cab
```

Remove work directories for the run name `boring_euler`:

```console
$ nextflow clean boring_euler -f

Removed work/92/c1a9cd9a96e0531d81ca69f5dc3bb7
Removed work/3f/70944c7a549b6221e1ccc7b4b21b62
Removed work/0e/2ebdba85f76f6068b21a1bcbf10cab
```

Remove the execution entries *except* for a specific execution:

```console
$ nextflow clean -but tiny_leavitt -f

Removed work/1f/f1ea9158fb23b53d5083953121d6b6
Removed work/bf/334115deec60929dc18edf0010032a
Removed work/a3/06521d75da296d4dd7f4f8caaddad8
```

Dry run to remove the execution data *before* a specific execution:

```console
$ nextflow clean -before tiny_leavitt -n

Would remove work/5d/ad76f7b7ab3500cf616814ef644b61
Would remove work/c4/69a82b080a477612ba8d8e4c27b579
Would remove work/be/a4fa2aa38f76fd324958c81c2e4603
Would remove work/54/39116773891c47a91e3c1733aad4de
```

Dry run to remove the execution data *after* a specific execution:

```console
$ nextflow clean -after focused_payne -n

Would remove work/1f/f1ea9158fb23b53d5083953121d6b6
Would remove work/bf/334115deec60929dc18edf0010032a
Would remove work/a3/06521d75da296d4dd7f4f8caaddad8
```

Dry run to remove the temporary execution data for a specific execution, while keeping the log files:

```console
$ nextflow clean -keep-logs tiny_leavitt -n

Would remove temp files from work/1f/f1ea9158fb23b53d5083953121d6b6
Would remove temp files from work/bf/334115deec60929dc18edf0010032a
Would remove temp files from work/a3/06521d75da296d4dd7f4f8caaddad8
```
