In this tutorial you can do some basic things with the public IPFS filesystem. This video tutorial provides instructions for how to install and run commands with the IPFS API using a Unix-type shell & operating system.
In this tutorial, you can follow along to understand the basics of how you, as a user, can access files in the public IPFS network. Follow along with the examples to learn about pinning and adding files, how files from IPFS can be previewed and inspected, and learn a bit about how that data is created and stored on IPFS.
In the previous tutorial, you learned how to start and stop an IPFS node in the command line.
Run ipfs daemon in the CLI to start your new node
When you run ipfs daemon, if you get the error: lock <path>/.ipfs/repo.lock: someone else has the lock, it means there is another instance running on your machine. Use the command killall ipfs and try again
You can stop your node by pressing cntrl + c twice in a row in the same terminal it’s running in, or typing killall ipfs in another window.
You can see your direct peers with the IPFS CLI, but with a simple command. By default, your ipfs node is seeded with a default list of trusted ‘bootstrap’ peers, which can be changed.
You can explore files on IPFS with the CLI tool as well. You can do this by installing IPFS Desktop or by using the URL for the web user interface (WebUI) at http://127.0.0.1:5001/webui which you should have seen when you ran ipfs init
➜ ~ ipfs daemon
Initializing daemon...
go-ipfs version: 0.11.0-67220edaa
Repo version: 11
System version: arm64/darwin
Golang version: go1.17.3
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/127.0.0.1/udp/4001/quic
Swarm listening on /ip4/192.168.64.1/tcp/4001
Swarm listening on /ip4/192.168.64.1/udp/4001/quic
... output omitted
WebUI: http://127.0.0.1:5001/webui
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready
Grab the CID of a file on IPFS and use it to read that file in the CLI (ideally a text file).
You can also take files shared on your local machine to your IPFS node, which is known as pinning. Simply use the command ipfs add directory/filename.extension. Make sure you have the correct path to the file from where you are working in the terminal.
Once you have started pinning files on your node, you can use the CLI to list them as well. You can choose the type of files listed, as well as how it is output in the CLI.
List the files on your node with ipfs pin ls --type=all
Now that you understand how the IPFS CLI works, take a minute to explore how data on IPFS is split up. Visit the IPFS DAG Inspector at dag.ipfs.tech, and drop a file from your local machine (any folder, any file) and see how it is broken up into UnixFS leaves.
You have already downloaded data from IPFS, added data to IPFS from your local machine, however, there is one more way you can share and store files. You can do this by pinning files from another node. What this does is make the file available to the public IPFS network, without having to download the file to your local directory/ system.
When you pin a file, it only exists as a part of your IPFS node, and is not a part of other filesystems on your computer. First, use the WebUI or IPFS Desktop to locate the CID of a file on the network.
Pin a file from the IPFS network to your local node with the command ipfs pin add <CID>
Now if you run the command with ipfs pin ls --type=all you should see the CID of the file you just pinned in the list.
When you pin files, this can be done in different ways. There are direct pins, which pin just a single block and no others in relation to it. Recursive pins pin a given block and all of its children. Indirect pins are the result of a given block’s parent being pinned recursively.