Bash Scripts, Linux

Get the size of your BTRFS Snapshots

If you want to get the size of your BTRFS snapshots you would probably use btrfs qgroup show.  This only shows you a list of IDs and the sizes are in bytes. I wrote a script that will convert the sizes from bytes to kilobytes, megabytes or gigabytes. It will combine the IDs with the name of each snapshot or subvolume from btrfs subvolume list to make each row a lot more meaningful.

In the end instead of seeing a list like this:
Screenshot from 2015-05-26 15:47:24

You’ll see:

Detailed information of each BTRFS snapshot
Detailed information of each BTRFS snapshot

Instead of meaningless IDs you now have the name of your BTRFS subvolumes or snapshots. Instead of a hard to decipher string of bytes it converts each amount into the most appropriate unit of measurement. You can also see the total amount of data that is being used by the snapshots.

For this to work you first need to enable  quotas. Run this command to enable quotas if you haven’t done so already:

sudo btrfs quota enable /

You can clone the project from github by running:
git clone

Or you can just go a wget on the script:

Set it to executable with:
chmod +x ./

Now you can just run the script with: ./

All the columns are pretty self explanatory. The Total column will tell you how much data is in that BTRFS subvolume. The Exclusive Data column is how much data is exclusive to that subvolume. Since BTRFS is a “copy on write” filesystem none of the data is replicated when you create a snapshot. It only needs to make a copy when something changes.

Leave your feedback here to let me know how it worked for you.

10 thoughts on “Get the size of your BTRFS Snapshots

  1. Wonderful work, was urgently needed!
    Yet I have a problem: while the shell works on all snapshots created by me, it does fail on the ones created by the command “apt-btrfs-snapshot” (on Ubuntu 16.04).
    # # here i have such a snapshot mounted on /target, as:
    # mount | grep /target
    /dev/mapper/luks-476a905e-8e64-4097-9ef6-c1e844ecb476 on /target type btrfs (rw,relatime,compress=lzo,ssd_spread,space_cache,subvolid=346,subvol=/@apt-snapshot-2016-12-26_21:33:48)
    # # now it comes:
    # /target
    /usr/local/bin/ line 55: can’t + 0: syntax error: invalid arithmetic operator (error token is “‘t + 0”)
    Snapshot / Subvolume ID Total Exclusive Data

    The same happens on many other variations of the snapshot name I have tried.
    Regards prometheos

    1. I fond by myself my error: now that I enabled BTRFS-Quotas globally, everything seems to work! (I had enabled quotas only locally, on my first btrfs device, i.e. my data container, not on /).

      Thanks again for Your code work!

  2. Nice tool!
    One little thing: I had to add
    at the beginning, as with my zsh the sh is the standard shell. And sh does not know about [[ ]]


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s