Inside the bash script, I need to get the total disk size and the currently used full disk size.
I know that I can get the total disk size without having to root with this command:
cat /sys/block/sda/size
This command will display the number of blocks on the SDA device. Multiply it by 512 and you will get the number of bytes on this device. This is enough for the total disk size.
Now for the used space. I want to get this value without root. I can assume that the device name is SDA. Now there is such a command: df I thought I could use this command, but it seems that this command only displays data from partitions already mounted.
Is there a way to get the total space used on the SDA without needing a root, and not all partitions need to be installed?
Suppose the following example:
/dev/sda1 80GB Linux partition 20GB Used /dev/sda2 80GB Linux Home partition 20GB Used /dev/sda3 100GB Windows Parition. 30GB Used
Suppose my SDA drive is partitioned as described above. But while I'm on Linux, my Windows partition (sda3) is not mounted.
The df output will give me a total of 40 GB, so it does not take an sda3 account.
Again, the question: Is there a way without root to get a total of 70 GB of used space?
source share