Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have Ubuntu server 12.04 installed with no GUI. I would like to list my hard drive and it's partitions along with how big each partition is using the command line.

share|improve this question
did you try my commands ? – nux Mar 8 '14 at 22:06
I tried all but inxi because my internet is down right now so I couldn't install it. All the other options were exactly what I was looking for and they each have there own perks, thank you. – Skateguy Mar 8 '14 at 23:01
ok hope you are ok now – nux Mar 8 '14 at 23:03
possible duplicate of How do I view all available HDD's/partitions? – Lưu Vĩnh Phúc Aug 4 '15 at 11:20
up vote 7 down vote accepted

Here are a few ways:

  • If you have an MBR partition table:

    terdon@oregano ~ $ sudo fdisk -l
    Disk /dev/sda: 500.1 GB, 500107862016 bytes
    255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x4b66b5d5
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1              63       80324       40131   de  Dell Utility
    /dev/sda2   *       81920    30801919    15360000    7  HPFS/NTFS/exFAT
    /dev/sda3        30801920   194643539    81920810    7  HPFS/NTFS/exFAT
    /dev/sda4       194643601   976773119   391064759+   f  W95 Ext'd (LBA)
    /dev/sda5       194643603   198836504     2096451    c  W95 FAT32 (LBA)
    /dev/sda6       342951936   960387071   308717568   83  Linux
    /dev/sda7       198840320   342949887    72054784   83  Linux
    /dev/sda8       960389120   976773119     8192000   82  Linux swap / Solaris

    or sudo sfdidk -l

    These do not give particularly human readable output though. The next choices are better.

  • For both GPT and MBR partition tables:

    terdon@oregano ~ $ sudo parted -l
    Model: ATA ST9500420AS (scsi)
    Disk /dev/sda: 500GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Number  Start   End     Size    Type      File system     Flags
     1      32.3kB  41.1MB  41.1MB  primary   fat16           diag
     2      41.9MB  15.8GB  15.7GB  primary   ntfs            boot
     3      15.8GB  99.7GB  83.9GB  primary   ntfs
     4      99.7GB  500GB   400GB   extended                  lba
     5      99.7GB  102GB   2147MB  logical   fat32           lba
     7      102GB   176GB   73.8GB  logical   ext4
     6      176GB   492GB   316GB   logical   ext4
     8      492GB   500GB   8389MB  logical   linux-swap(v1)
    Model: ST950032 5AS (scsi)
    Disk /dev/sdb: 500GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Number  Start   End    Size   Type     File system  Flags
     1      32.3kB  500GB  500GB  primary  ntfs
  • lsblk

    terdon@oregano ~ $ lsblk
    sda      8:0    0 465.8G  0 disk 
    ├─sda1   8:1    0  39.2M  0 part 
    ├─sda2   8:2    0  14.7G  0 part 
    ├─sda3   8:3    0  78.1G  0 part 
    ├─sda4   8:4    0     1K  0 part 
    ├─sda5   8:5    0     2G  0 part 
    ├─sda6   8:6    0 294.4G  0 part /home
    ├─sda7   8:7    0  68.7G  0 part /
    └─sda8   8:8    0   7.8G  0 part [SWAP]
    sdb      8:16   0 465.8G  0 disk 
    └─sdb1   8:17   0 465.8G  0 part /test
    sr0     11:0    1  1024M  0 rom  
  • Install inxi then run

    terdon@oregano ~ $ inxi -D
    Drives:    HDD Total Size: 1000.2GB (70.1% used) 1: id: /dev/sda model: ST9500420AS size: 500.1GB 
               2: id: /dev/sdb model: 5AS size: 500.1GB 
share|improve this answer

In terminal :

sudo fdisk -l

Type your password.

lsblk command :

share|improve this answer
Why not copy paste instead of posting the images? That would fasten up loading this answer. – i08in Mar 8 '14 at 22:39
i think images would be better for understanding – nux Mar 8 '14 at 22:44
I agree with you about the images thing, my brain just likes them better. – Skateguy Mar 8 '14 at 23:04
On the other hand, images don't let you copy/paste if necessary (not very relevant here, I know) and they really slow down the page which can be important for slow connections. – terdon Mar 8 '14 at 23:10

Here's couple of other approaches:


The short version of lshw conveniently lists the size of disks in the description

sudo lshw -short | awk '/disk|volume/'            
/0/1/0.0.0    /dev/sda    disk        120GB Radeon R7
/0/1/0.0.0/1  /dev/sda1   volume      111GiB EXT4 volume
/0/2/0.0.0    /dev/cdrom  disk        DVDRAM GT20N

And for more detailed info use lshw -class volume,disk


udiscsctl has info option which coupled with -b (for block-device) flag, can show detailed information. Using a simple for loop and awk, we can make it show partition and size information specifically. Here is my example:

$ for device in /dev/sd* ; do udisksctl info  -b $device | awk '/[[:blank:]]Device:/; /Size/' ;done                
    Device:                     /dev/sda
    Size:                       120034123776
    Device:                     /dev/sda1
    Size:                       120032591872
    Size:               120032591872

df command

df command shows information about all currently mounted filesystems. Again, we can use this command directly, but also clean up the output using awk

df -h | awk 'NR==1 ;/\/dev\/sd*/'                                                                                
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       110G   68G   37G  66% /

Here we just print the header and use -h flag that makes size be printed in human-readable format

/sys/class/block/sd* files

Inside /sys/class/block/ folder you will find files related to block devices( which typically refer to physical memory devices ) . In particular we want to focus on any file that starts with sd letters.

For instance, I have one hard drive with only one partition. Thus /sys/class/block/sda refers to my whole hard-drive, while /sys/class/block/sda1 refers to my Ubuntu partition.

Inside each folder for each device, you will find the size file , which lists how many blocks of 512 MB there are on the device. So the true size is number of blocks x 521.

Again, with little command line magic, we get:

$ for device in /sys/class/block/sd*; do printf "%s " $device; bc <<< "$(cat $device/size)*512" ; done             
/sys/class/block/sda 120034123776
/sys/class/block/sda1 120032591872

Or a bit shorter with awk:

$ awk '{print substr(FILENAME,18)" "$1*512}' /sys/class/block/sd*/size                                             
sda/size 120034123776
sda1/size 120032591872
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.