Real time file sizes?

In order to take a look at the sizes of my VM disk images, I tried ls -lh (as it was suggested here). And here is what it returned:

leo@ubuntu:~$ sudo ls -lh /var/lib/libvirt/images

total 65G
-rw------- 1 root root  26G Jul 21 15:20 a.qcow2
-rw------- 1 root root 801G Jul 21 10:44 b.qcow2
-rw------- 1 root root 401G Jul 21 11:42 c.qcow2

I found the output surprizing for two reasons:

  1. It appears to be inconsistent: total 65G vs 26G + 801G + 401G
  2. It appears to be wrong: my SSD is only 1T.

The large sizes (801G and 401G) correspond to the VM sizes when powered on, but when I ran the command, all VMs were shut off.

Is there a better command to get real time file sizes?


Solution 1:

If you use the --size, -s, option then you will also get the actually currently allocated size of the file. Example for my VM's where the virtual disks are 51 gigabytes each:

doug@s19:~/temp-git-phoronix/phoronix-test-suite$ ls -lh ~/vm
total 58G
-rw------- 1 root root 51G Jul 15 22:39 desk-ff.img
-rw------- 1 root root 51G Jul 15 22:38 desk-hh.img
-rw------- 1 root root 51G Jul 15 22:38 desk-ii.img
-rw------- 1 root root 51G Jun 20 23:31 serv-xx.img
doug@s19:~/temp-git-phoronix/phoronix-test-suite$ ls -lh --size ~/vm
total 58G
 22G -rw------- 1 root root 51G Jul 15 22:39 desk-ff.img
 15G -rw------- 1 root root 51G Jul 15 22:38 desk-hh.img
 15G -rw------- 1 root root 51G Jul 15 22:38 desk-ii.img
7.0G -rw------- 1 root root 51G Jun 20 23:31 serv-xx.img