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
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”.
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.
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.
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.
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.
Je veux intégrer cette plateforme.
toujours bienvenu Nathan:)