# clean

> Remove qsv-generated cache files (`.idx` index, `stats` & `frequency` caches) to reduce clutter & simplify data packaging. With `--stale`, only removes caches whose source changed or is gone. Opt-in flags also clean `schema`, `validate` & `moarstats` outputs.

**[Table of Contents](TableOfContents.md)** | **Source: [src/cmd/clean.rs](https://github.com/dathere/qsv/blob/master/src/cmd/clean.rs)**

<a name="nav"></a>
[Description](#description) | [Examples](#examples) | [Usage](#usage) | [Clean Options](#clean-options) | [Common Options](#common-options)

<a name="description"></a>

## Description [↩](#nav)

Removes qsv-generated cache files to reduce clutter and simplify data packaging.

By default, clean removes the three auto-regenerable CACHES qsv writes next to a
source file:  

* <file>.idx                                              (index)
* <stem>.stats.csv / .stats.weighted.csv / .stats.csv.json
/ .stats.csv.data.jsonl                                 (stats cache)
* <stem>.freq.csv.data.jsonl                              (frequency cache)

Only files that are VERIFIABLY generated by qsv are removed, so a user file that
merely happens to be named e.g. report.stats.csv is never touched (qsv stats
caches are only removed when their companion .stats.csv.json sidecar is present).

clean is, by default, a DRY-RUN: it only lists what it WOULD remove (and the
bytes that would be reclaimed). Pass --force to actually delete.

User OUTPUTS from schema, validate and moarstats are NOT caches and are only
removed when you ask for them explicitly with --schema / --validate / --moarstats
(or --all).


<a name="examples"></a>

## Examples [↩](#nav)

Preview the caches qsv would remove from the current directory:  
```console
qsv clean
```

Actually remove them:  
```console
qsv clean --force
```

Remove only STALE or orphaned caches (source changed, or source is gone),
recursively, from a specific directory:  
```console
qsv clean --stale --recursive --force ./data
```

Remove just the caches & outputs associated with one file:  
```console
qsv clean --all --force data.csv
```

For the tests, see <https://github.com/dathere/qsv/blob/master/tests/test_clean.rs>.

<a name="usage"></a>

## Usage [↩](#nav)

```console
qsv clean [options] [<input>]
qsv clean --help
```

<a name="clean-options"></a>

## Clean Options [↩](#nav)

| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Type | Description | Default |
|--------|------|-------------|--------|
| &nbsp;`‑‑stale`&nbsp; | flag | Only remove STALE or ORPHANED caches: a cache whose source file is newer than the cache, or whose source file no longer exists. |  |
| &nbsp;`‑r,`<br>`‑‑recursive`&nbsp; | flag | Recurse into subdirectories when <input> is a directory. |  |
| &nbsp;`‑n,`<br>`‑‑dry‑run`&nbsp; | flag | Preview only; never delete. Wins over --force if both are given (this is also the default when neither is set). |  |
| &nbsp;`‑f,`<br>`‑‑force`&nbsp; | flag | Actually delete the files. |  |
| &nbsp;`‑‑index`&nbsp; | flag | Index (.idx) caches. [default category] |  |
| &nbsp;`‑‑stats`&nbsp; | flag | Stats caches. [default category] |  |
| &nbsp;`‑‑frequency`&nbsp; | flag | Frequency caches. [default category] |  |
| &nbsp;`‑‑schema`&nbsp; | flag | schema .schema.json / .pschema.json outputs. |  |
| &nbsp;`‑‑validate`&nbsp; | flag | validate .valid / .invalid / .validation-errors.tsv outputs. |  |
| &nbsp;`‑‑moarstats`&nbsp; | flag | moarstats .stats.bivariate[.joined].csv outputs. |  |
| &nbsp;`‑‑all`&nbsp; | flag | Select every category above. |  |

<a name="common-options"></a>

## Common Options [↩](#nav)

| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Option&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Type | Description | Default |
|--------|------|-------------|--------|
| &nbsp;`‑h,`<br>`‑‑help`&nbsp; | flag | Display this message |  |
| &nbsp;`‑q,`<br>`‑‑quiet`&nbsp; | flag | Do not print the per-file / summary report. |  |

---
**Source:** [`src/cmd/clean.rs`](https://github.com/dathere/qsv/blob/master/src/cmd/clean.rs)
| **[Table of Contents](TableOfContents.md)** | **[README](../../README.md)**
