How to view unallocated free space on a hard disk through terminal [closed]
Use GNU parted
and print free
command:
root@sandbox:~# partedGNU Parted 2.3Using /dev/sdaWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) print freeModel: VMware Virtual disk (scsi)Disk /dev/sda: 64.4GBSector size (logical/physical): 512B/512BPartition Table: msdosNumber Start End Size Type File system Flags 32.3kB 1049kB 1016kB Free Space 1 1049kB 256MB 255MB primary ext2 boot 256MB 257MB 1048kB Free Space 2 257MB 64.4GB 64.2GB extended 5 257MB 64.4GB 64.2GB logical lvm 64.4GB 64.4GB 1049kB Free Space
To see in TB:
# parted /dev/sda unit TB print free | grep 'Free Space' | tail -n1 | awk '{print $3}'
To see in GB:
# parted /dev/sda unit GB print free | grep 'Free Space' | tail -n1 | awk '{print $3}'
To see in MB:
# parted /dev/sda unit MB print free | grep 'Free Space' | tail -n1 | awk '{print $3}'
To see in bytes:
# parted /dev/sda unit B print free | grep 'Free Space' | tail -n1 | awk '{print $3}'
To see in %:
# parted /dev/sda unit '%' print free | grep 'Free Space' | tail -n1 | awk '{print $3}'
To see in sectors:
# parted /dev/sda unit s print free | grep 'Free Space' | tail -n1 | awk '{print $3}'
Change /dev/sda
to whatever device you are trying to find the information about. If you are using the result in any calculations, make sure to trim the trailing characters.
This is an old question, but I wanted to give my answer as well.
Since we're talking about free available space, we should talk about sectors, since no partitioning or sizing of sectors is done.
For us human beings this doesn't make much sense. To have human-readable information we must translate this number into bytes.So, we have a disk already partitioned and we want to know how much space we may use. I personally don't like the parted
solution because my brain-memory for commands is already taken. There is also cfdisk
, which gives you free space. But I think fdisk is the quickest solution: it's plain and simple, with nothing to install: execute fdisk /dev/sdx
and then enter v into the interactive shell. It will gives you the number of sectors still free.
2004-54-0 [17:03:33][root@minimac:~]$> fdisk /dev/sdaWelcome to fdisk (util-linux 2.23.2)...Command (m for help): vRemaining 1713 unallocated 512-byte sectors
We still have 1713 sectors at 512 bytes each. So, because you love terminal (in 2012, who knows now?) we do echo $(((1713*512)/1024))k
, which is 1713 sectors multiplied for 512 bytes (divided by 1024 to have KB), which gives 856k.. not even 900 KB.. and I need another disk..