31

I've added a bunch of files via ipfs add. How do I unpin and remove all of these at once?

jclay
  • 988
  • 1
  • 7
  • 10

3 Answers3

52

to unpin all added content:

ipfs pin ls --type recursive | cut -d' ' -f1 | xargs -n1 ipfs pin rm

then optionally run storage garbage collection to actually remove things:

ipfs repo gc

Daniel
  • 4,525
  • 3
  • 38
  • 52
jclay
  • 988
  • 1
  • 7
  • 10
2

Additionally to jclay's answer, you might also want to delete everything on MFS:

ipfs files ls / | while read f; do ipfs files rm -r "/$f"; done

(Obligatory warning that this won't work if paths contain newlines.)

Caesar
  • 6,733
  • 4
  • 38
  • 44
  • 1
    I needed to add a slash in the filename like: ```ipfs files ls / | while read f; do ipfs files rm -r "/$f"; done``` – splch May 26 '21 at 20:30
0

Based on Daniel's answer, here's how to do it in a Docker container

docker exec ipfs_container_name ipfs pin ls --type recursive | cut -d' ' -f1 | xargs -n1 docker exec ipfs_container_name ipfs pin rm

Replace ipfs_container_name with the name of your docker container.

esot321c
  • 1
  • 1