How do I check how much free space left on a device to create a partition

As root, type in a shell:

# cfdisk /dev/sdX  #Where /dev/sdX is the device 

it will show you something like this:

cfdisk (util-linux-ng 2.18)

                          Disk Drive: /dev/sdb
                    Size: 3926949888 bytes, 3926 MB
          Heads: 255   Sectors per Track: 63   Cylinders: 477

Name        Flags      Part Type  FS Type          [Label]        Size (MB)

sdb1                    Primary   vfat             [ABDEL]          1998.75
sdb2        Boot        Primary   ext3             [linx]           1924.72

if the device has free space it will be shown.

Note: cfdisk in fact is a terminal based partition editor.


You could also use parted in command mode:

parted /dev/sda unit MiB print free

output:

Model: ATA M4-CT128M4SSD2 (scsi)
Disk /dev/sda: 122104MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start     End        Size      Type     File system     Flags
        0.03MiB   1.00MiB    0.97MiB            Free Space
 1      1.00MiB   28672MiB   28671MiB  primary  ext4
        28672MiB  28673MiB   1.00MiB            Free Space
 2      28673MiB  30720MiB   2047MiB   primary  linux-swap(v1)
        30720MiB  30721MiB   1.00MiB            Free Space
 3      30721MiB  92160MiB   61439MiB  primary  ntfs
        92160MiB  122104MiB  29944MiB           Free Space

If you want just the total free space you could run:

parted /dev/sda unit MiB print free | awk '/Free Space/{c++; sum += $3} \
END{if(c == 0) print "No Free Space"; else print sum" MiB"}'
29947 MiB

You can use different units to display the size: B up to TB, KiB up to TiB etc (see man parted for details).


To report all drives/partitions and their remaining sizes:

df -h

or:

fdisk -l

For folders use the disk usage command with the -sh options:

du -sh

Note: -h is for showing human readable (i.e. 34 GB instead of 340000000 blocks/bytes)