# Delete based on directory size

**URL:** <https://forum.ansible.com/t/delete-based-on-directory-size/30307>\
**Category:** Ansible Project\
**Created:** [May 11, 2019, 12:00pm UTC](https://forum.ansible.com/t/delete-based-on-directory-size/30307 "2019-05-11T12:00:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_Britton](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@Nicholas\_Britton](https://forum.ansible.com/u/Nicholas_Britton)\
**Post date:** [May 11, 2019, 12:00pm UTC](https://forum.ansible.com/t/delete-based-on-directory-size/30307/1 "2019-05-11T12:00:16Z")

</div>

I have been looking for a module for something similar to the du command. I would like to have a play that looks at the log directory to detect if it's a certian size or larger and if so find the sub folders with gbs of data and remove or tar that data up.

So far I am not finding that and parsing the return of the du command is not is not somethig I am having luck with.

Has anyone tried to do something similar? Have any ideas or pointers for me?

---

<div class="post-metadata">

**Author:** ![dan\_linder](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dan_linder/32/3833_2.png) [@dan\_linder](https://forum.ansible.com/u/dan_linder)\
**Post date:** [May 11, 2019, 8:31pm UTC](https://forum.ansible.com/t/delete-based-on-directory-size/30307/2 "2019-05-11T20:31:10Z")

</div>

Does this help?

I created a directory structure with four files:

`$ find /tmp/dirsize/ -ls | cut -c 18- drwxrwxr-x 5 dan dan 100 May 11 14:59 /tmp/dirsize/ drwxrwxr-x 2 dan dan 60 May 11 15:00 /tmp/dirsize/d3 -rw-rw-r-- 1 dan dan 5242880 May 11 15:00 /tmp/dirsize/d3/5M.file drwxrwxr-x 2 dan dan 60 May 11 15:00 /tmp/dirsize/d2 -rw-rw-r-- 1 dan dan 3145728 May 11 15:00 /tmp/dirsize/d2/3M.file drwxrwxr-x 2 dan dan 80 May 11 15:00 /tmp/dirsize/d1 -rw-rw-r-- 1 dan dan 3145728 May 11 15:00 /tmp/dirsize/d1/3M.file -rw-rw-r-- 1 dan dan 6291456 May 11 14:59 /tmp/dirsize/d1/6M.file`

Then using this playbook:

`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 13, 2019, 2:20pm UTC](https://forum.ansible.com/t/delete-based-on-directory-size/30307/3 "2019-05-13T14:20:51Z")

</div>

You can use the 'find' module and register the results:

ansible -m find -a 'path=~/ size=200k file\_type=directory' localhost
