'How do I retrieve the hash of ipfs object?

After I add a file to ipfs using ipfs add hello - how to do I retrieve the hash for the file if I lose it?

I guess I'm expecting ipfs info <filepath> or something similar?



Solution 1:[1]

If you want to see what the hash of a file would be, without actually uploading it to IPFS, you can run ipfs add --only-hash, or ipfs add -n for short.

Solution 2:[2]

just run ipfs add hello again...

Solution 3:[3]

Make sure ipfs daemon is running before proceeding.

ipfs get theHashOfTheItem in the command line will print out the raw data/ text of the block corresponding to that particular hash

To get a list of objects with the hash that is hosted on your computer, you may run the daemon using ipfs daemon followed by going to and checking under Files.

http://localhost:5001/webui

I remember reading a way to get the list of hashes via the command line, but I can't seem to remember it. Once I get it, I shall post the details about that here as well.

Not ideal, but checking the information each hash stores, either by using the command shared on top or clicking on the files itself within the browser should let you find the hash you are looking for.

Solution 4:[4]

Since you've added the file/folder, it will be pinned to your ipfs repo. Run the command

ipfs pin ls

This will list all the objects of the files/folder pinned to your repo

Solution 5:[5]

Spent an hour doing this and turns out you can do a simple ipfs files stat /path/to/object to get an output like:

$ ipfs files stat /folder-2/text.txt QmcNsPV7QZFHKb2DNn8GWsU5dtd8zH5DNRa31geC63ceb4 Size: 14 CumulativeSize: 72 ChildBlocks: 1 Type: file

If you want to script this, do a simple | head -n 1 to get the hash.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stan James
Solution 2 significance
Solution 3 Varun Agarwal
Solution 4 Arun
Solution 5 Rohitt Vashishtha