check storage space in ubuntu | how to check hard disk size in ubuntu terminal

show total of disk space

$ df -h --total

which will show it in one line as

  • (1) total space
  • (2) total space used
  • (3) total space still available
  • (4) percentage of drive used.

All of this in gigabytes.

I mapped this to a shell command dspace and when I type that into terminal it instantly shows me my disk space usage.

$ df -h --total | grep total

lists the size of each partition

$ lsblk

1. Checking File System Disk Space

The “df” command displays the information of file system device names, disk blocks, total disk space used, available disk space, percentage of usage and mount points on a file system.

ubuntu@www:~$ df
Filesystem     1K-blocks    Used Available Use% Mounted on
udev              491680       0    491680   0% /dev
tmpfs             100764     780     99984   1% /run
/dev/xvda1     101583780 7599572  93967824   8% /
tmpfs             503804       0    503804   0% /dev/shm
tmpfs               5120       0      5120   0% /run/lock
tmpfs             503804       0    503804   0% /sys/fs/cgroup
/dev/loop0         91264   91264         0 100% /snap/core/8268
/dev/loop1         18432   18432         0 100% /snap/amazon-ssm-agent/1480
/dev/loop2         18432   18432         0 100% /snap/amazon-ssm-agent/1455
/dev/loop3         91264   91264         0 100% /snap/core/8213
tmpfs             100760       0    100760   0% /run/user/1000

2. Display Disk Space in Human Readable Format

As you see in the first example, the output is difficult to read or understand. By default df command shows disk space information in bytes which is difficult to understand for humans. We can easily understand if the results are in megabytes and gigabytes.

Don’t worry, the good df command has an option to display information in human readable format like in MB and GB. You just need to add -h flag to see.

ubuntu@www:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            481M     0  481M   0% /dev
tmpfs            99M  780K   98M   1% /run
/dev/xvda1       97G  7.3G   90G   8% /
tmpfs           492M     0  492M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           492M     0  492M   0% /sys/fs/cgroup
/dev/loop0       90M   90M     0 100% /snap/core/8268
/dev/loop1       18M   18M     0 100% /snap/amazon-ssm-agent/1480
/dev/loop2       18M   18M     0 100% /snap/amazon-ssm-agent/1455
/dev/loop3       90M   90M     0 100% /snap/core/8213
tmpfs            99M     0   99M   0% /run/user/1000

3. Display information of all file systems

If you want to see all file systems including which has zero block sizes, pass parameter -a or -all along with df command. The output would be similar to this.

ubuntu@www:~$ df -all
Filesystem     1K-blocks    Used Available Use% Mounted on
sysfs                  0       0         0    - /sys
proc                   0       0         0    - /proc
udev              491680       0    491680   0% /dev
devpts                 0       0         0    - /dev/pts
tmpfs             100764     780     99984   1% /run
/dev/xvda1     101583780 7517872  94049524   8% /
securityfs             0       0         0    - /sys/kernel/security
tmpfs             503804       0    503804   0% /dev/shm
tmpfs               5120       0      5120   0% /run/lock
tmpfs             503804       0    503804   0% /sys/fs/cgroup
cgroup                 0       0         0    - /sys/fs/cgroup/unified
cgroup                 0       0         0    - /sys/fs/cgroup/systemd
pstore                 0       0         0    - /sys/fs/pstore
cgroup                 0       0         0    - /sys/fs/cgroup/devices
cgroup                 0       0         0    - /sys/fs/cgroup/cpu,cpuacct
cgroup                 0       0         0    - /sys/fs/cgroup/rdma
cgroup                 0       0         0    - /sys/fs/cgroup/perf_event
cgroup                 0       0         0    - /sys/fs/cgroup/pids
cgroup                 0       0         0    - /sys/fs/cgroup/hugetlb
cgroup                 0       0         0    - /sys/fs/cgroup/net_cls,net_prio
cgroup                 0       0         0    - /sys/fs/cgroup/blkio
cgroup                 0       0         0    - /sys/fs/cgroup/memory
cgroup                 0       0         0    - /sys/fs/cgroup/freezer
cgroup                 0       0         0    - /sys/fs/cgroup/cpuset
systemd-1              -       -         -    - /proc/sys/fs/binfmt_misc
hugetlbfs              0       0         0    - /dev/hugepages
mqueue                 0       0         0    - /dev/mqueue
debugfs                0       0         0    - /sys/kernel/debug
fusectl                0       0         0    - /sys/fs/fuse/connections
configfs               0       0         0    - /sys/kernel/config
/dev/loop0         91264   91264         0 100% /snap/core/8268
/dev/loop1         18432   18432         0 100% /snap/amazon-ssm-agent/1480
/dev/loop2         18432   18432         0 100% /snap/amazon-ssm-agent/1455
/dev/loop3         91264   91264         0 100% /snap/core/8213
lxcfs                  0       0         0    - /var/lib/lxcfs
binfmt_misc            0       0         0    - /proc/sys/fs/binfmt_misc
tmpfs             100760       0    100760   0% /run/user/1000

4. Display File System details in Bytes

To display all file system information and usage in 1 K blocks , pass the option ‘-k‘  as follows.

ubuntu@www:~$ df -k
Filesystem     1K-blocks    Used Available Use% Mounted on
udev              491680       0    491680   0% /dev
tmpfs             100764     784     99980   1% /run
/dev/xvda1     101583780 7600328  93967068   8% /
tmpfs             503804       0    503804   0% /dev/shm
tmpfs               5120       0      5120   0% /run/lock
tmpfs             503804       0    503804   0% /sys/fs/cgroup
/dev/loop0         91264   91264         0 100% /snap/core/8268
/dev/loop1         18432   18432         0 100% /snap/amazon-ssm-agent/1480
/dev/loop2         18432   18432         0 100% /snap/amazon-ssm-agent/1455
/dev/loop3         91264   91264         0 100% /snap/core/8213
tmpfs             100760       0    100760   0% /run/user/1000

5. Display File System Information in MB

To display all file system information and usage in MB or megabytes  , pass the option ‘-m‘.

ubuntu@www:~$ df -m
Filesystem     1M-blocks  Used Available Use% Mounted on
udev                 481     0       481   0% /dev
tmpfs                 99     1        98   1% /run
/dev/xvda1         99203  7343     91845   8% /
tmpfs                492     0       492   0% /dev/shm
tmpfs                  5     0         5   0% /run/lock
tmpfs                492     0       492   0% /sys/fs/cgroup
/dev/loop0            90    90         0 100% /snap/core/8268
/dev/loop1            18    18         0 100% /snap/amazon-ssm-agent/1480
/dev/loop2            18    18         0 100% /snap/amazon-ssm-agent/1455
/dev/loop3            90    90         0 100% /snap/core/8213
tmpfs                 99     0        99   0% /run/user/1000

6. Display File System Information in GB

To display all file system details and usage in GB or gigabytes  , pass the option ‘-h‘.

ubuntu@www:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            481M     0  481M   0% /dev
tmpfs            99M  780K   98M   1% /run
/dev/xvda1       97G  7.3G   90G   8% /
tmpfs           492M     0  492M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           492M     0  492M   0% /sys/fs/cgroup
/dev/loop0       90M   90M     0 100% /snap/core/8268
/dev/loop1       18M   18M     0 100% /snap/amazon-ssm-agent/1480
/dev/loop2       18M   18M     0 100% /snap/amazon-ssm-agent/1455
/dev/loop3       90M   90M     0 100% /snap/core/8213
tmpfs            99M     0   99M   0% /run/user/1000

7. Display /home file system information

You can see only /home file system device infomation by executing below df command.

ubuntu@www:~$ df -h /home
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       97G  7.3G   90G   8% /

8. Display File System Type in Linux

To see the type of each file system pass the -T option. It gives output with file system types column. You could see the type of each file system listed such as ext4, ext3, tempfs, devtmpfs and etc.

ubuntu@www:~$ df -T
Filesystem     Type     1K-blocks    Used Available Use% Mounted on
udev           devtmpfs    491680       0    491680   0% /dev
tmpfs          tmpfs       100764     780     99984   1% /run
/dev/xvda1     ext4     101583780 7602896  93964500   8% /
tmpfs          tmpfs       503804       0    503804   0% /dev/shm
tmpfs          tmpfs         5120       0      5120   0% /run/lock
tmpfs          tmpfs       503804       0    503804   0% /sys/fs/cgroup
/dev/loop0     squashfs     91264   91264         0 100% /snap/core/8268
/dev/loop1     squashfs     18432   18432         0 100% /snap/amazon-ssm-agent/1480
/dev/loop2     squashfs     18432   18432         0 100% /snap/amazon-ssm-agent/1455
/dev/loop3     squashfs     91264   91264         0 100% /snap/core/8213
tmpfs          tmpfs       100760       0    100760   0% /run/user/1000

9. Include or Exclude only certain File System Types.

If you want to see only ext4 file systems, use df command with option -t

If you want to see all file system types except ext4, then pass -x option and type ( ext3, ext4) to exclude from the output.

 df -t tmpfs
Filesystem     1K-blocks  Used Available Use% Mounted on
tmpfs             100764   780     99984   1% /run
tmpfs             503804     0    503804   0% /dev/shm
tmpfs               5120     0      5120   0% /run/lock
tmpfs             503804     0    503804   0% /sys/fs/cgroup
tmpfs             100760     0    100760   0% /run/user/1000

10. Display df Command Options and Help

You can see all the available options with df command by typing below command.

$ df --help
Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             include pseudo, duplicate, inaccessible file systems
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
  -h, --human-readable  print sizes in powers of 1024 (e.g., 1023M)
  -H, --si              print sizes in powers of 1000 (e.g., 1.1G)
  -i, --inodes          list inode information instead of block usage
  -k                    like --block-size=1K
  -l, --local           limit listing to local file systems
      --no-sync         do not invoke sync before getting usage info (default)
      --output[=FIELD_LIST]  use the output format defined by FIELD_LIST,
                               or print all fields if FIELD_LIST is omitted.
  -P, --portability     use the POSIX output format
      --sync            invoke sync before getting usage info
      --total           elide all entries insignificant to available space,
                          and produce a grand total
  -t, --type=TYPE       limit listing to file systems of type TYPE
  -T, --print-type      print file system type
  -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
  -v                    (ignored)
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

The SIZE argument is an integer and optional unit (example: 10K is 10*1024).
Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).

FIELD_LIST is a comma-separated list of columns to be included.  Valid
field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',
'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report df translation bugs to <http://translationproject.org/team/>
Full documentation at: <http://www.gnu.org/software/coreutils/df>
or available locally via: info '(coreutils) df invocation'