How to check a hash whether exist on local ipfs repo or not?

Here is a simple ipfs add operation.

[mountedDirectory]$ ipfs add -r folder 
added QmWce5WcDhjTXp8ycQf92EMNndwNwmTigVEAQ9xpmZWazJ folder/
added Qmc2yZrduQapeK47vkNeT5pCYSXjsZ3x6yzK8an7JLiMq2 folder
 123 B / 4.12 KiB [=====>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------]   2.92%

Later I would like to check that does Qmc2yZrduQapeK47vkNeT5pCYSXjsZ3x6yzK8an7JLiMq2 exists on my local ipfs repo.

How could I do achieve it?

Is following code correct way to do it? I assume if a hash is pinned its already stored in the local ipfs repo.

$ ipfs pin ls --type recursive | grep -c 'Qmc2yZrduQapeK47vkNeT5pCYSXjsZ3x6yzK8an7JLiMq2'

I think this post has an answer to your question:

Edit: pinned hashes are stored locally, but they are not the only hashes that get stored locally.

1 Like