# Deleting log files after they have finished processing

**URL:** https://discuss.elastic.co/t/deleting-log-files-after-they-have-finished-processing/246382
**Category:** Elastic Tips and Common Fixes
**Tags:** filebeat, logstash
**Created:** [August 26, 2020, 4:17am UTC](https://discuss.elastic.co/t/deleting-log-files-after-they-have-finished-processing/246382 "2020-08-26T04:17:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [August 26, 2020, 4:17am UTC](https://discuss.elastic.co/t/deleting-log-files-after-they-have-finished-processing/246382/1 "2020-08-26T04:17:44Z")

</div>

**Filebeat** does not have the capabilities to handle deleting files from a host's filesystem after they have been processed. The best option is to use a cron job or scheduled task on your OS to delete them after a safe period of time.

You will want to consider configuring options like [`ignore_older`](https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-input-log.html#filebeat-input-log-ignore-older) and the various `close` options, to be explicit around when Filebeat will no longer read the files.

**Logstash** can use [`mode`](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html#plugins-inputs-file-mode) on the `file` input, to run a script or command to delete the files. An example of this would look like;

```auto
input {

 file {
    path => "/path/to/log/files/*.log"
    mode => "read"
    file_completed_action => "delete"
  }
}

```

It is important to note that using `mode => "read"` means that Logstash considers these files to be complete - ie they are not being written to - and so will delete these files as soon as it reaches the end of the file.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 4, 2022, 8:11am UTC](https://discuss.elastic.co/t/deleting-log-files-after-they-have-finished-processing/246382/2 "2022-11-04T08:11:25Z")

</div>


