Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view unallocated free space on a hard disk through terminal [closed]

I want to view the unallocated free space on my hard disk through terminal. I've burned my brains searching the internet for a possible solution, but all in vain.

I used all sorts of commands like df, du, fdisk, parted, etc. It tells me about the disks that are mounted and unmounted, but what about the unallocated space that I've left free?

Of course I can view it using the 'Disk Utility' app provided by Fedora, but since I LOVE being in the terminal I'd like to view in it.

Can anyone please help me with a solution?

like image 732
AniketGM Avatar asked Sep 07 '12 07:09

AniketGM


People also ask

How do I see unallocated hard drive space in Linux?

While also finding the unallocated space in a hard disk using command line # fdisk /dev/sda will display the total space and total cylinder value. Now check the last cylinder value and subtract it from the total cylinder value. Hence the final value * 1000 gives you the unallocated disk space.

How do I list unallocated space in CMD?

Open the Command Prompt as Administrator. Type diskpart and hit Enter. Once you enter to the diskpart screen type list disk and hit Enter. Now a list of the disks will be shown, type select disk x (the X is the disk number that has an unallocated space) and hit Enter.


2 Answers

Use GNU parted and print free command:

root@sandbox:~# parted GNU Parted 2.3 Using /dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print free Model: VMware Virtual disk (scsi) Disk /dev/sda: 64.4GB Sector size (logical/physical): 512B/512B Partition Table: msdos  Number  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 
like image 193
Burhan Khalid Avatar answered Oct 24 '22 03:10

Burhan Khalid


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.

like image 39
user2618594 Avatar answered Oct 24 '22 04:10

user2618594