How to get information about your filesystems with the Linux command line.

The Linux command line allows a user to get good information about filesystems using the shell prompt. Here are some examples.

Print a list of all filesystems and their sizes in megabytes.

ubuntu ~ $ df -Hla -BMB
Filesystem     1MB-blocks    Used Available Use% Mounted on
sysfs                 0MB     0MB       0MB    - /sys
proc                  0MB     0MB       0MB    - /proc
udev                516MB     1MB     516MB   1% /dev
devpts                0MB     0MB       0MB    - /dev/pts
tmpfs               105MB     1MB     104MB   1% /run
/dev/xvda1        31563MB 25670MB    4504MB  86% /
none                  1MB     0MB       1MB   0% /sys/fs/cgroup
none                  0MB     0MB       0MB    - /sys/fs/fuse/connections
none                  0MB     0MB       0MB    - /sys/kernel/debug
none                  0MB     0MB       0MB    - /sys/kernel/security
none                  6MB     0MB       6MB   0% /run/lock
none                521MB     0MB     521MB   0% /run/shm
none                105MB     0MB     105MB   0% /run/user
none                  0MB     0MB       0MB    - /sys/fs/pstore
systemd               0MB     0MB       0MB    - /sys/fs/cgroup/systemd

List all block devices in your Linux machine and their mountpoint.

ubuntu ~ $ lsblk
xvda    202:0    0  30G  0 disk
└─xvda1 202:1    0  30G  0 part /

The parted utility allows a superuser to list all filesystems in a Linux system.

Just run sudo parted and then the print all command.

sudo parted
GNU Parted 2.3
Using /dev/xvda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print all
Model: Xen Virtual Block Device (xvd)
Disk /dev/xvda: 32.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number  Start   End     Size    Type     File system  Flags
 1      8225kB  32.2GB  32.2GB  primary  ext4         boot

The fdisk command will also list all filesystems.

ubuntu ~ $ sudo fdisk -l
Disk /dev/xvda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 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: 0x00000000
    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *       16065    62910539    31447237+  83  Linux

Sfdisk is a good alternative, this will display partition sizes in megabytes.

ubuntu ~ $ sudo sfdisk -l -uM
Disk /dev/xvda: 3916 cylinders, 255 heads, 63 sectors/track
Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0
   Device Boot Start   End    MiB    #blocks   Id  System
/dev/xvda1   *     7+ 30718- 30711-  31447237+  83  Linux
/dev/xvda2         0      -      0          0    0  Empty
/dev/xvda3         0      -      0          0    0  Empty
/dev/xvda4         0      -      0          0    0  Empty

There is also a Python script, pydf, this will list all partitions on your hard drive.

Firstly, install this script.

sudo apt-get install pydf

Then run this script to get an idea of how much space is left on your filesystems.

ubuntu ~ $ pydf
Filesystem Size Used Avail Use%                                  Mounted on
/dev/xvda1  29G  24G 4294M 81.3 [########################......] /\

To get the UUID of a Linux filesystem, run this command and get the UUID that matches the name, such as /dev/sda1.

ubuntu ~ $ blkid
/dev/xvda1: LABEL="cloudimg-rootfs" UUID="ee515a1e-7735-4529-822f-4cc9e7632cd3" TYPE="ext4"

The output of the pydf script is the best, using a simple graph to show how much disk space is taken up. This means that it is the quickest to interpret. The output of the df -Hla -BMB command can be the hardest to interpret as it outputs so much, but I will leave it up to you which you choose to use. Linux has so many options right now it can be quite overwhelming. Just choose the option that suits you.

No comments have been made. Use this form to start the conversation :)

Leave a Reply