How can I find out the size of a filesystem in Linux? By that I mean the exact number of bytes that are used from the partition, not just the output of df
, as that can differ from the true size when compression or deduplication is used on the filesystem.
The size of the partition itself can be printed with:
$ lsblk -b
or
$ blockdev --getsize64 /dev/sda
I am looking for something similar for the filesystem.
PS: This is for LVM grow/shrink stuff. I am mostly interested in ext2/3/4 and btrfs, but any other filesystem info is appreciated as well.
If you want filesystem information and not partition/volume information, I think you'll have to use filesystem-specific tools.
In the case of the extN systems, that would be
dumpe2fs
. Anddumpe2fs
doesn't directly print the size in bytes, as far as I can tell. It does, however, print the block count and the size of blocks, so you can parse the output instead:In my case, this size is slightly different from the partition size:
The partition size is 29999983104 bytes, 2560 bytes more than a multiple of the block size, which is why the size reported by
dumpe2fs
is less.It depends on the filesystem you want to investigate:
ext2, ext3, ext4 file system
You have to multiply block count and block size to get number of bytes.
ISO-9660 file system
The unit for volume size is logical blocks, so you have to multiply volume size and logical block size to get number of bytes.
BTRFS file system
As one btrfs can include several devices, the command takes the mountpoint as argument
For btrfs, you can use: