# How to get the CID of a folder

**URL:** <https://discuss.ipfs.tech/t/how-to-get-the-cid-of-a-folder/12614>\
**Category:** Kubo\
**Tags:** go-ipfs, multihash, files\
**Created:** [November 9, 2021, 5:52pm UTC](https://discuss.ipfs.tech/t/how-to-get-the-cid-of-a-folder/12614 "2021-11-09T17:52:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaniellMesquita](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/daniellmesquita/32/7300_2.png) [@DaniellMesquita](https://discuss.ipfs.tech/u/DaniellMesquita)\
**Post date:** [November 9, 2021, 5:52pm UTC](https://discuss.ipfs.tech/t/how-to-get-the-cid-of-a-folder/12614/1 "2021-11-09T17:52:19Z")

</div>

# Question

The closest and only answer I saw is: `ipfs add -r {folder-name}`

But it adds the whole folder to IPFS (but you don’t want to really add, but simply to get its CID) and displays all CIDs from all files.

A better command I came with is `ipfs add -qr --only-hash {folder-name}`, because it only gets the CID instead of adding all the files; but, still, it outputs all CIDs instead of only the folder’s CID you want.

# Working answer

How to display the CID of a folder:  
`ipfs add -qr --only-hash {folder-name} | tail -n 1`

Display base32/CID v2 of a folder:  
`ipfs add -qr --only-hash {folder-name} | tail -n 1 | ipfs cid base32`

## Updated answer by @Jorropo

How to display the CID of a folder:  
`ipfs add -Qr --only-hash {folder-name}`

Display base32/CID v2 of a folder:  
`ipfs add -Qr --only-hash {folder-name} | ipfs cid base32`

## Bonus

Display the CID of a single file:  
`ipfs add -q --only-hash {file-name}`

Display the base32/CID v2 of a single file:  
`ipfs add -q --only-hash {file-name} | ipfs cid base32`

---

<div class="post-metadata">

**Author:** ![Jorropo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/jorropo/32/3230_2.png) [@Jorropo](https://discuss.ipfs.tech/u/Jorropo)\
**Post date:** [November 9, 2021, 5:55pm UTC](https://discuss.ipfs.tech/t/how-to-get-the-cid-of-a-folder/12614/2 "2021-11-09T17:55:23Z")

</div>

```auto
ipfs add -Qr --only-hash {folder-name}

```

There is `-q` for `--quiet` and `-Q` for `--quieter`

---

<div class="post-metadata">

**Author:** ![DaniellMesquita](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ipfs.tech/daniellmesquita/32/7300_2.png) [@DaniellMesquita](https://discuss.ipfs.tech/u/DaniellMesquita)\
**Post date:** [November 9, 2021, 6:09pm UTC](https://discuss.ipfs.tech/t/how-to-get-the-cid-of-a-folder/12614/3 "2021-11-09T18:09:32Z")

</div>

Many thanks.

I’ve updated it.

Months ago I was searching how to get the CID of a folder and didn’t found any answer before, so I had to figure myself a hack until I discovered this case sensitive `Q` flag by you. Many thanks, again; because now I can use a standard command instead of a glue, tricky workaround.

It will be important for [Web3Updater](https://github.com/danimesq/Web3Updater) so it can get the CID of the bare git repo it adds to ENS as update.
