# How to exclude a sub directory and all of it's files

**URL:** <https://discuss.elastic.co/t/how-to-exclude-a-sub-directory-and-all-of-its-files/137317>\
**Category:** Beats\
**Tags:** filebeat\
**Created:** [June 25, 2018, 9:16pm UTC](https://discuss.elastic.co/t/how-to-exclude-a-sub-directory-and-all-of-its-files/137317 "2018-06-25T21:16:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamlearner123](https://avatars.discourse-cdn.com/v4/letter/i/bcef8e/32.png) [@iamlearner123](https://discuss.elastic.co/u/iamlearner123)\
**Post date:** [June 25, 2018, 9:16pm UTC](https://discuss.elastic.co/t/how-to-exclude-a-sub-directory-and-all-of-its-files/137317/1 "2018-06-25T21:16:50Z")

</div>

Hello,

I am trying to exclude a sub directory and all of its files in file beat . In the documentation, i know that there is a flag called "_exclude\_files_". But having hard time to figure out how to use it to exclude a sub directory.

For example,

This log path contains _/var/log/syslog/port_ below sub directories

10.1.123.145  
qpn001data1  
qpn002data1  
old  
vqpn0001patha1  
vqpn0002patha1  
vqpn0003patha1

But i want to eliminate the sub directory "old" all the files in it .. Is it possible to do it with "exclude\_files ?

Thanks

---

<div class="post-metadata">

**Author:** ![pierhugues](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierhugues/32/48383_2.png) [@pierhugues](https://discuss.elastic.co/u/pierhugues)\
**Post date:** [June 26, 2018, 2:59pm UTC](https://discuss.elastic.co/t/how-to-exclude-a-sub-directory-and-all-of-its-files/137317/2 "2018-06-26T14:59:18Z")

</div>

@iamlearner123 You should be able to use `exclude_files` with a regular expression that match the directory that you want to exclude.

I think the following should work in your case.

```auto
 exclude_files:
    - '^/var/log/syslog/port/'

```

---

<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:** [July 23, 2018, 9:16pm UTC](https://discuss.elastic.co/t/how-to-exclude-a-sub-directory-and-all-of-its-files/137317/3 "2018-07-23T21:16:49Z")

</div>

This topic was automatically closed after 28 days. New replies are no longer allowed.
