# Logstash How to read only name of the file

**URL:** <https://discuss.elastic.co/t/logstash-how-to-read-only-name-of-the-file/276096>\
**Category:** Logstash\
**Created:** [June 16, 2021, 7:57am UTC](https://discuss.elastic.co/t/logstash-how-to-read-only-name-of-the-file/276096 "2021-06-16T07:57:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Betorov](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@Betorov](https://discuss.elastic.co/u/Betorov)\
**Post date:** [June 16, 2021, 7:57am UTC](https://discuss.elastic.co/t/logstash-how-to-read-only-name-of-the-file/276096/1 "2021-06-16T07:57:10Z")

</div>

Hi I'am new to elasticsearch.  
I wanted to know if there was a possible way to read only the names of the files and ignore the contents inside (I must ignore it to prevent error. I saw this posts but it didn't work for me me:

> [@How to read only filenames in filbeat without reading log file content](https://discuss.elastic.co/t/how-to-read-only-filenames-in-filbeat-without-reading-log-file-content/186139):
>
> Someone help me in understanding ,how to read log file names without reading file content in file beat. Thanks in advance..

> [@Read filenames using logstash](https://discuss.elastic.co/t/read-filenames-using-logstash/124758):
>
> Hi All, I need to read to read filenames available in a directory in unix server and send it to elastic search to create dashboards in Kibana. Filename itself contains all the information that is required to create my dashboards. eg.: US9PTW46.14.SUB#2.D031918.T075518.p.US9TW001.FIA.stdout this is one of the filename which follows the below format: ...D\<Date\_MMDDYY\>.T\<Time\_HHMMSS\>.,.. I think I can use logstash with file input plugin and tweak multiline codec to read whole file as one entry…

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [June 16, 2021, 4:58pm UTC](https://discuss.elastic.co/t/logstash-how-to-read-only-name-of-the-file/276096/2 "2021-06-16T16:58:53Z")

</div>

It could be done using filebeat to read the files and then in logstash

```
mutate { remove_field => ["message"] }
if [offset] != 0 { drop {} }

```

but reading all the files and discarding the contents is ridiculously wasteful. Why not feed the output from `ls -l` to logstash?

---

<div class="post-metadata">

**Author:** ![Betorov](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@Betorov](https://discuss.elastic.co/u/Betorov)\
**Post date:** [June 17, 2021, 6:27am UTC](https://discuss.elastic.co/t/logstash-how-to-read-only-name-of-the-file/276096/3 "2021-06-17T06:27:27Z")

</div>

Hi @Badger, thanks for your reply.  
I tried :

```auto
mutate { remove_field => ["message"] }
if [offset] != 0 { drop {} }

```

But it don't send any date to elasticsearch 🙁.  
This one could be a good solution:

> Why not feed the output from `ls -l` to logstash?

But I don't know how 😅. I am using the file input (I need him to go through my folder), can i keep the file input and feed the input with ls -l?

---

<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 15, 2021, 6:27am UTC](https://discuss.elastic.co/t/logstash-how-to-read-only-name-of-the-file/276096/4 "2021-07-15T06:27:34Z")

</div>

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