next command diskutil info disk0s2 | grep -Ei 'Total.+([0-9]){10,}' | grep -Eio '[0-9]{10,}' diskutil info disk0s2 | grep -Ei 'Total.+([0-9]){10,}' | grep -Eio '[0-9]{10,}' diskutil info disk0s2 | grep -Ei 'Total.+([0-9]){10,}' | grep -Eio '[0-9]{10,}' (assuming you have disk0s2) returns the size of the / partion disk in bytes.
Assuming your drive is at least 127.2 GigbaGytes or ~ 127.000.000.000 bytes , you will get one s2 partition size from this command, which will work the same way for the entire drive.
diskutil info disk0 | grep -Ei 'Total.+([0-9]){10,}' | grep -Eio '[0-9]{10,}'
my 128GB SSDs for hard drives are 128035676160 , and 127175917568 and one partition minus 200 MB for EFI
Change Total in regular expression Free , and you will get available free space for the selected section. Use size in some backup scripts pv + dd + pigz ;-)
eg:
DISK0S2_SIZE=`diskutil info disk0s2 | \ grep -Ei 'Total.+([0-9]){10,}' | \ grep -Eio '[0-9]{10,}'` | \ sudo dd if=/dev/rdisk0s2 bs=1m | \ pv -s $DISK0S2_SIZE | \ pigz -9z > /path/to/backup.zz
Here we assume that I want disk0s2 z-ziped with 9 compression (11 - max or the --best flag). Say hello to the excellent progress indicator, since one of them is never know-how ,-)
source share