9 Linux Commands For Linux Disk Usage

LINUX-Disk-Usage-commands-ipcisco

How to Check Linux Disk Space?

Linux disk usage is one of the critical information for a Linux Administrator. A Linux admin generally use different commands to check Linux disk usage and memory availability. In this lesson, we will focus on these commands and learn how to check Linux disk utilization.  So, how to check Linux disk space? Let’s see alternative commands to check Linux disk space

 


You can also check Linux Cheat Sheet for More Linux Commands!


 

Linux Df Command

The first answer of how to check Linux disk space question is Linux df command. With df command, which we can check Linux disk usage quickly. We can use this command without any option. By the way, df is the abbreviation for “disk free”.

 

root@kali:/home/kali# df

Filesystem     1K-blocks    Used Available Use% Mounted on

udev              995816       0    995816   0% /dev

tmpfs             203304    6256    197048   4% /run

/dev/sda1       79981124 8114248  67761048  11% /

tmpfs            1016512       0   1016512   0% /dev/shm

tmpfs               5120       0      5120   0% /run/lock

tmpfs            1016512       0   1016512   0% /sys/fs/cgroup

tmpfs             203300      12    203288   1% /run/user/1000

tmpfs             203300       4    203296   1% /run/user/132

 

Beside using df command alone, we can also use some options with it to learn more information about Linux disk usage. For example, if we use -T option, as df -T, we can also learn filesystem type of (xfs, ext2, ext3, ext4, etc.) each block.

 

root@kali:/home/kali# df -T

Filesystem     Type     1K-blocks    Used Available Use% Mounted on

udev           devtmpfs    995816       0    995816   0% /dev

tmpfs          tmpfs       203304    6236    197068   4% /run

/dev/sda1      ext4      79981124 8114256  67761040  11% /

tmpfs          tmpfs      1016512       0   1016512   0% /dev/shm

tmpfs          tmpfs         5120       0      5120   0% /run/lock

tmpfs          tmpfs      1016512       0   1016512   0% /sys/fs/cgroup

tmpfs          tmpfs       203300      12    203288   1% /run/user/1000

 

Another option is df -a. With this option, we can learn disk usage for all files, also the files whose available field is 0.

 

root@kali:/home/kali# df -a

Filesystem     1K-blocks    Used Available Use% Mounted on

sysfs                  0       0         0    - /sys

proc                   0       0         0    - /proc

udev              995816       0    995816   0% /dev

devpts                 0       0         0    - /dev/pts

tmpfs             203304    6236    197068   4% /run

/dev/sda1       79981124 8114256  67761040  11% /

securityfs             0       0         0    - /sys/kernel/security

tmpfs            1016512       0   1016512   0% /dev/shm

tmpfs               5120       0      5120   0% /run/lock

tmpfs            1016512       0   1016512   0% /sys/fs/cgroup

cgroup2                0       0         0    - /sys/fs/cgroup/unified

 

And the other one is -I option which shows used and free inodes space.

 

root@kali:/home/kali# df -i

Filesystem      Inodes  IUsed   IFree IUse% Mounted on

udev            248954    396  248558    1% /dev

tmpfs           254128    641  253487    1% /run

/dev/sda1      5111808 308088 4803720    7% /

tmpfs           254128      1  254127    1% /dev/shm

tmpfs           254128      2  254126    1% /run/lock

tmpfs           254128     17  254111    1% /sys/fs/cgroup

tmpfs           254128     21  254107    1% /run/user/1000

 

We can also use –h option to display the information with a human readable format.

 

root@kali:/home/kali# df -h

Filesystem      Size  Used Avail Use% Mounted on

udev            973M     0  973M   0% /dev

tmpfs           199M  6.1M  193M   4% /run

/dev/sda1        77G  7.8G   65G  11% /

tmpfs           993M     0  993M   0% /dev/shm

tmpfs           5.0M     0  5.0M   0% /run/lock

tmpfs           993M     0  993M   0% /sys/fs/cgroup

tmpfs           199M   12K  199M   1% /run/user/1000

 


 

Linux Du Command

The second answer of how to check Linux disk space question is, using linux du command. With du command of Linux, we can display disk usage of files and folders.

 

root@kali:/home/kali# du

4       ./.config/gtk-3.0

24      ./.config/xfce4/desktop

8       ./.config/xfce4/panel/launcher-7

8       ./.config/xfce4/panel/launcher-6

24      ./.config/xfce4/panel

68      ./.config/xfce4/xfconf/xfce-perchannel-xml

72      ./.config/xfce4/xfconf

4       ./.config/xfce4/xfwm4

132     ./.config/xfce4

8       ./.config/kazam

16      ./.config/Thunar

60      ./.config/pulse

 

If you would like to display disk usage for all the files, you can use, as du -a.

 

root@kali:/home/kali# du -a

0       ./abc1

4       ./.config/gtk-3.0

4       ./.config/xfce4/desktop/icons.screen0-813x823.rc

4       ./.config/xfce4/desktop/icons.screen0-1904x910.rc

4       ./.config/xfce4/desktop/icons.screen0-1904x1033.rc

0       ./.config/xfce4/desktop/icons.screen.latest.rc

4       ./.config/xfce4/desktop/icons.screen0-1264x673.rc

4       ./.config/xfce4/desktop/icons.screen0-1653x823.rc

24      ./.config/xfce4/desktop

4       ./.config/xfce4/panel/launcher-7/15801475692.desktop

 

 

 Option -s shows the total disk usage by a particular file or directory in the Linux system.

 

root@kali:/home/kali# du -s

28420

 

If you would like to learn each file’s modification time in Linux system, you can use du –time option.

 

root@kali:/home/kali# du --time

4       2021-12-20 04:50        ./.config/gtk-3.0

24      2022-09-26 04:32        ./.config/xfce4/desktop

8       2020-01-27 12:52        ./.config/xfce4/panel/launcher-7

8       2020-01-27 12:52        ./.config/xfce4/panel/launcher-6

24      2021-06-11 08:12        ./.config/xfce4/panel

68      2022-09-20 07:33        ./.config/xfce4/xfconf/xfce-perchannel-xml

72      2022-09-20 07:33        ./.config/xfce4/xfconf

4       2020-01-27 12:52        ./.config/xfce4/xfwm4

132     2022-09-26 04:32        ./.config/xfce4

8       2021-12-20 04:19        ./.config/kazam

LINUX-Disk-Usage-commands-ipcisco


 

Linux free Command

Another command to check linux disk usage is Linux free command. This command displays the amount of free/used disk space as memory and swap in Linux system. We can use linux free command alone to display disk usage. We can also use different options for alternative views.

 

First of all, we can use -h option for human readable format. This command will show disk usage with better view for us.

 

root@kali:/home/kali# free -h

total        used        free      shared  buff/cache   available

Mem:          1.9Gi       467Mi       1.1Gi        14Mi       380Mi       1.3Gi

Swap:         2.0Gi          0B       2.0Gi

 

Above, the output of the command is in Mebibyte format. If you would like to see the result in megabytes, you can use –mega option with free command. Or you can use –giga to is it in gigabytes.

 

root@kali:/home/kali# free --mega

total        used        free      shared  buff/cache   available

Mem:           2081         489        1189          15         402        1414

Swap:          2144           0        2144

 

Sometimes you can want to display disk usage, a couple of times. For this check, you can use free -c option. After this command, you should define the times that you would like to display this command. Below, we will display Linux disk usage, three times.

 

root@kali:/home/kali# free -c 3

total        used        free      shared  buff/cache   available

Mem:        2033028      482236     1152800       17520      397992     1375368

Swap:       2094076           0     2094076




total        used        free      shared  buff/cache   available

Mem:        2033028      482244     1152792       17520      397992     1375376

Swap:       2094076           0     2094076




total        used        free      shared  buff/cache   available

Mem:        2033028      482244     1152792       17520      397992     1375376

Swap:       2094076           0     2094076

 

If a couple of times is not enough for you, you can refresh free command at a given interval. To do this, you can use free -s option. With the below command, the output of free command will be displayed every two seconds. If you would like to break, you can use CTRL-C and quit.

 

root@kali:/home/kali# free -s 2

total        used        free      shared  buff/cache   available

Mem:        2033028      482616     1147244       17520      403168     1374828

Swap:       2094076           0     2094076




total        used        free      shared  buff/cache   available

Mem:        2033028      482624     1147236       17520      403168     1374820

Swap:       2094076           0     2094076




total        used        free      shared  buff/cache   available

Mem:        2033028      482624     1147236       17520      403168     1374820

Swap:       2094076           0     2094076


^C

 

We can also use -l option to show low and high memory statistics on the system.

 

root@kali:/home/kali# free -l

total        used        free      shared  buff/cache   available

Mem:        2033028      482592     1147088       17520      403348     1374788

Low:        2033028      885940     1147088

High:             0           0           0

Swap:       2094076           0     2094076

 

And lastly, with -t option, we can see the total of each column. Memory and swap totals.

 

root@kali:/home/kali# free -t

total        used        free      shared  buff/cache   available

Mem:        2033028      482560     1147096       17520      403372     1374824

Swap:       2094076           0     2094076

Total:      4127104      482560     3241172

 


 

fdisk command

Another command to display information about Linux disk space is fdisk command. With fdisk command, we can display the partition on Linux system and the details about it. We will use -l option with this command.

 

root@kali:/home/kali# fdisk -l

Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors

Disk model: VMware Virtual S

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0x096af559




Device     Boot     Start       End   Sectors Size Id Type

/dev/sda1  *         2048 163579903 163577856  78G 83 Linux

/dev/sda2       163581950 167770111   4188162   2G  5 Extended

/dev/sda5       163581952 167770111   4188160   2G 82 Linux swap / Solaris

 


 

sfdisk command

Another command to display information about disks is sfdisk. Again, we will use sfdisk command with -l option.

 

root@kali:/home/kali# sfdisk -l

Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors

Disk model: VMware Virtual S

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0x096af559




Device     Boot     Start       End   Sectors Size Id Type

/dev/sda1  *         2048 163579903 163577856  78G 83 Linux

/dev/sda2       163581950 167770111   4188162   2G  5 Extended

/dev/sda5       163581952 167770111   4188160   2G 82 Linux swap / Solaris

 


 

Cfdisk Partition Editor

If you would like to use a Linux partition editor, Linux cfdisk command is for you. With this editor, you can create, modify and manage partitions.

 

root@kali:/home/kali# cfdisk

 

If you want to work with a specific partition, you can define it after cfdisk command like below:

 

root@kali:/home/kali# cfdisk /dev/sda1

 


 

Linux parted command

With Linux parted command, we can display and modify partition in Linux system. We can use this command with -l option.

 

root@kali:/home/kali# parted -l

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sda: 85.9GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Disk Flags:




Number  Start   End     Size    Type      File system     Flags

1      1049kB  83.8GB  83.8GB  primary   ext4            boot

2      83.8GB  85.9GB  2144MB  extended

5      83.8GB  85.9GB  2144MB  logical   linux-swap(v1)

 


 

lsblk command

With lsblk command of Linux, we can list the storage blocks, partitions etc. This command gives the total size but not the used space by these partitions.

 

root@kali:/home/kali# lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda      8:0    0   80G  0 disk

├─sda1   8:1    0   78G  0 part /

├─sda2   8:2    0    1K  0 part

└─sda5   8:5    0    2G  0 part [SWAP]

sr0     11:0    1 1024M  0 rom

 

blkid command

With blkid command, we can print partitions again. Anad again like lsblk command, blkid command do not print the used size by partition.

 

root@kali:/home/kali# blkid

/dev/sda1: UUID="d339729e-3161-42a4-83f2-bcdf68c192b2" TYPE="ext4" PARTUUID="096af559-01"

/dev/sda5: UUID="372746d0-df7d-485a-a21e-1475e9102454" TYPE="swap" PARTUUID="096af559-05"

 


 

Summary of Linux Disk Usage

In Linux, disk usage is very important. Linux system administrators always check this information for a good system performance. For Linux disk usage, system administrators use generally du, df, free commands. Beside these commands, there are other alternatives. In this lesson, we have answered, how to check Linux disk space question with nine different disk usage Linux commands.

 

Back to: Kali Linux Course

2 Responses to “9 Linux Commands For Linux Disk Usage”


Leave a Reply

Your email address will not be published. Required fields are marked *