# How to keep orginal file name when store it on IPFS?

**URL:** <https://discuss.ipfs.tech/t/how-to-keep-orginal-file-name-when-store-it-on-ipfs/4545>\
**Category:** Help\
**Created:** [December 26, 2018, 1:46pm UTC](https://discuss.ipfs.tech/t/how-to-keep-orginal-file-name-when-store-it-on-ipfs/4545 "2018-12-26T13:46:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Medow](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/medow/32/2354_2.png) [@Medow](https://discuss.ipfs.tech/u/Medow)\
**Post date:** [December 26, 2018, 1:46pm UTC](https://discuss.ipfs.tech/t/how-to-keep-orginal-file-name-when-store-it-on-ipfs/4545/1 "2018-12-26T13:46:39Z")

</div>

I notice that IPFSS doesn’t maintain file name on the files upload to ipfs.  
For example:  
[https://ipfs.io/ipfs/QmUrNv5yofTVJcCZSsWM7YBd4ppzvpLDx9a6iVwp3Tp29b](https://ipfs.io/ipfs/QmUrNv5yofTVJcCZSsWM7YBd4ppzvpLDx9a6iVwp3Tp29b)  
this file orginal name is: eula.1028.txt  
But when i download it from IPFS network it doesn’t downloaded with the orginal file name, it just append hash to the name.  
How to make file downloaded with it is own name.  
Thanks.

---

<div class="post-metadata">

**Author:** ![leerspace](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@leerspace](https://discuss.ipfs.tech/u/leerspace)\
**Post date:** [December 26, 2018, 2:28pm UTC](https://discuss.ipfs.tech/t/how-to-keep-orginal-file-name-when-store-it-on-ipfs/4545/2 "2018-12-26T14:28:39Z")

</div>

When adding the file to IPFS, you can preserve the filename by wrapping it with a directory using the `-w` option.

For example, `ipfs add -w eula.1028.txt` would result in a directory containing the file with the filename preserved.

---

<div class="post-metadata">

**Author:** ![Medow](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/medow/32/2354_2.png) [@Medow](https://discuss.ipfs.tech/u/Medow)\
**Post date:** [December 26, 2018, 8:56pm UTC](https://discuss.ipfs.tech/t/how-to-keep-orginal-file-name-when-store-it-on-ipfs/4545/4 "2018-12-26T20:56:09Z")

</div>

@leerspace , Thanks for reply.  
But how to do this when we add a folder with 100s of file?

---

<div class="post-metadata">

**Author:** ![adamskrodzki](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/adamskrodzki/32/2940_2.png) [@adamskrodzki](https://discuss.ipfs.tech/u/adamskrodzki)\
**Post date:** [December 26, 2018, 9:11pm UTC](https://discuss.ipfs.tech/t/how-to-keep-orginal-file-name-when-store-it-on-ipfs/4545/5 "2018-12-26T21:11:10Z")

</div>

Just add a folder with files in it instead of 100 files. If You add folder all filenames are preserved

---

<div class="post-metadata">

**Author:** ![Medow](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/medow/32/2354_2.png) [@Medow](https://discuss.ipfs.tech/u/Medow)\
**Post date:** [December 26, 2018, 9:17pm UTC](https://discuss.ipfs.tech/t/how-to-keep-orginal-file-name-when-store-it-on-ipfs/4545/6 "2018-12-26T21:17:57Z")

</div>

@adamskrodzki , Thanks adam.  
I know i can add the folder instead of the files and it will keep the files name.  
But all my files on that folders will be exposed to every one by browsing the parent folder. While i need to share each file alone using it is own hash.  
And if i resolve each file on that folder alone and sharing it with it own hash , then i will come back to the first problem the orginal file name will override with hash name.

---

<div class="post-metadata">

**Author:** ![leerspace](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@leerspace](https://discuss.ipfs.tech/u/leerspace)\
**Post date:** [December 26, 2018, 10:56pm UTC](https://discuss.ipfs.tech/t/how-to-keep-orginal-file-name-when-store-it-on-ipfs/4545/7 "2018-12-26T22:56:54Z")

</div>

If you can’t add the parent folder and each file has to be added separately, then you can do this on linux using a simple one-liner.

```auto
find path/to/folder -maxdepth 1 -type f -exec ipfs add -w -Q --pin=false {} \;

```

edit: you can remove the `--pin=false` part if you want to keep the default behavior to pin content after adding.

edit 2: adding the `-q` option to only output the final hash for each directory-wrapped file

edit 3: changing the `-q` to a `-Q`

---

<div class="post-metadata">

**Author:** ![Medow](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/medow/32/2354_2.png) [@Medow](https://discuss.ipfs.tech/u/Medow)\
**Post date:** [December 27, 2018, 9:05pm UTC](https://discuss.ipfs.tech/t/how-to-keep-orginal-file-name-when-store-it-on-ipfs/4545/8 "2018-12-27T21:05:44Z")

</div>

@leerspace , Thanks.  
This is a perfect solution .  
If i make it like this:  
find path/to/folder -maxdepth 1 -type f -exec ipfs add -w -q {} ; 0 2\>&1 | tee /tmp/fileshash.txt  
The files will be pinned and result will be safed on fileshash.txt?  
Correct?

---

<div class="post-metadata">

**Author:** ![leerspace](https://avatars.discourse-cdn.com/v4/letter/l/94ad74/32.png) [@leerspace](https://discuss.ipfs.tech/u/leerspace)\
**Post date:** [December 27, 2018, 10:24pm UTC](https://discuss.ipfs.tech/t/how-to-keep-orginal-file-name-when-store-it-on-ipfs/4545/9 "2018-12-27T22:24:20Z")

</div>

I made a mistake in my previous post; the `-q` should instead be a `-Q` to limit it only to the final hash for each directory-wrapped file. The former will spit out the hash for both the file and the parent directory.

> [@Medow](#):
>
> find path/to/folder -maxdepth 1 -type f -exec ipfs add -w -q {} ; 0 2\>&1 | tee /tmp/fileshash.txt

That doesn’t work for me (I don’t know what `0 2>&1` is supposed to do), but this does.

```bash
find path/to/folder -maxdepth 1 -type f -exec ipfs add -w -Q {} 2>&1 \; | tee /tmp/filehash.txt

```

If you want to write out the filename and the parent hash on each line separated by a tab, you could also do something like this.

```bash
find path/to/folder -maxdepth 1 -type f -exec sh -c "printf {}; printf '\t'; ipfs add --pin=false -w -Q {} 2>&1" \; | tee /tmp/filehash.txt

```

---

<div class="post-metadata">

**Author:** ![Medow](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/medow/32/2354_2.png) [@Medow](https://discuss.ipfs.tech/u/Medow)\
**Post date:** [December 27, 2018, 10:29pm UTC](https://discuss.ipfs.tech/t/how-to-keep-orginal-file-name-when-store-it-on-ipfs/4545/10 "2018-12-27T22:29:26Z")

</div>

Sorry , it is a typo. I mean  
`2>&1`  
Your solution work perfectly , Thank you very much for your help. You safe my day.  
Regards.
