# Cleaning work dirs before retrying

**URL:** <https://cylc.discourse.group/t/cleaning-work-dirs-before-retrying/891>\
**Category:** Cylc Support\
**Created:** [February 19, 2024, 9:40am UTC](https://cylc.discourse.group/t/cleaning-work-dirs-before-retrying/891 "2024-02-19T09:40:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abarral](https://avatars.discourse-cdn.com/v4/letter/a/3ab097/32.png) [@abarral](https://cylc.discourse.group/u/abarral)\
**Post date:** [February 19, 2024, 9:40am UTC](https://cylc.discourse.group/t/cleaning-work-dirs-before-retrying/891/1 "2024-02-19T09:40:26Z")

</div>

When a task fails during execution, it can be reran, either using e.g. using `execution retry` or via the web UI (which uses `cylc trigger`).

However, if the job failed midway, it likely has generated a number of files in its `work` directory, which will interfere with the new execution.

Of course, an advanced job may either look at `$CYLC_TASK_TRY_NUMBER` or simply perform an absurd number of checks to make sure every single output exists and isn’t corrupted before recreating it, but for the vast majority of jobs it seems to be that it would be easier to wipe the work dir before executing again.

**Is there a built-in utility when triggering a new task to wipe its work dir, or do we need to add** `rm -rf *` **at the start of every single script ?**

---

<div class="post-metadata">

**Author:** ![oliver.sanders](https://yyz2.discourse-cdn.com/free1/user_avatar/cylc.discourse.group/oliver.sanders/32/110_2.png) [@oliver.sanders](https://cylc.discourse.group/u/oliver.sanders)\
**Post date:** [February 19, 2024, 10:43am UTC](https://cylc.discourse.group/t/cleaning-work-dirs-before-retrying/891/2 "2024-02-19T10:43:10Z")

</div>

Hi,

How tasks manage their space in the `work/` directory is down to them. Generally, we don’t `rm -rf *` but instead write tasks to be robust against being rerun, or in many cases get them to continue from where they left off.

If you want to wipe the work directory, there’s no Cylc utility that does the job more simply than `rm -rf *`, however the `cylc clean` command can also be used to this effect, though may also attempt to remove the files on other hosts:

```auto
# remove a task's work directory on all hosts
cylc clean --rm 'work/<cycle>/<task>'

```
