Search code examples
phplinuxdiskspace

php get free space /dev/sda linux


I have stage code

$totalSpace =  74.5GB ;

$freespacespace = disk_free_space('/dev/sda')/1024/1024;

$usedSpace = $totalSpace - $freespacespace;

==>

total Space: 74.5GB ;

free spacespace: 1.46 GB ;

used Space: 73.04GB ;

While in command

i have

NAME                         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                            8:0    0  74.5G  0 disk
|-sda1                         8:1    0   243M  0 part /boot
|-sda2                         8:2    0     1K  0 part
`-sda5                         8:5    0  74.3G  0 part
  |-ubuntu--vg-root (dm-0)   252:0    0  71.3G  0 lvm  /
  `-ubuntu--vg-swap_1 (dm-1) 252:1    0     3G  0 lvm  [SWAP]
dev_php@ubuntu:~$ df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-root   71G  2.8G   64G   5% /
udev                         1.5G  4.0K  1.5G   1% /dev
tmpfs                        301M  348K  300M   1% /run
none                         5.0M     0  5.0M   0% /run/lock
none                         1.5G     0  1.5G   0% /run/shm
/dev/sda1                    236M   32M  192M  14% /boot

How to get free space?

free space in one of the partitions on that drive disk /dev/sda


Solution

  • Get the free space on a partition using disk_free_space("/dev/sda1")

    Just note that there are multiple partitions on this drive so any attempt to do disk size - space in partition will not give you an accurate view of how much space is used in that partition as the partition itself is not the full size of the disk.