Disk space usage in Linux is crucial for maintaining system health and performance. Regularly checking disk space is vital as it ensures efficient utilization of storage resources, prevents system slowdowns or crashes due to full disks, and allows for proactive management of available space.
In this article, we’ll explore simple and handy Linux commands that can be very helpful to check how much space is left on the system disks. Whether we’re seasoned Linux users or just getting started, these commands will empower us to efficiently manage our storages and keep our systems running smoothly. Let’s dive into the world of disk space monitoring with Linux!
df (disk free):
The ‘df’ command in Linux stands for “disk free” and is used to display information about the disk space usage of file systems. Its provided the summary of available and used disk space on the mounted file systems.
To make use of this command to check disk space, run the below commands as shown.
$ df
$ df -h
Filesystem Size Used Avail Use% Mounted on tmpfs 390M 1,2M 389M 1% /run /dev/sda2 98G 14G 79G 15% / tmpfs 2,0G 0 2,0G 0% /dev/shm tmpfs 5,0M 4,0K 5,0M 1% /run/lock /dev/sda1 511M 6,1M 505M 2% /boot/efi tmpfs 390M 124K 390M 1% /run/user/1000
Here, we have used the ‘-h’ parameter which is to show the output in human readable format.
inode (index nodes)
The inodes are the data structures used in Linux based file systems where each file or directory is represented by an inode. So, checking the free number of inodes is as important as checking the free disk space. To check the free number of inodes we can make use of the command below.
$ df -ih
Filesystem Inodes IUsed IFree IUse% Mounted on
tmpfs 488K 825 487K 1% /run /dev/sda2 6,3M 618K 5,7M 10% / tmpfs 488K 1 488K 1% /dev/shm tmpfs 488K 5 488K 1% /run/lock /dev/sda1 0 0 0 - /boot/efi tmpfs 98K 133 98K 1% /run/user/1000
Here in the output we can see the total number of inodes, used and free on its respective mount points.
To get the list of all the available arguments and instructions for using the ‘df’ command we can follow its ‘help’ command.
$ df - -help
du (disk usage):
The ‘du’ command in Linux stands for “disk usage” and is used to estimate and display the disk space. It provides a summary of space usage for specified files or directories and can recursively analyze subdirectories to report total usage.
To show the practical examples of this command line utility, we are going to run some of its most useful commands.
$ du
$ du -h
$ du -h --max-depth=1 -x /
$ du -h --max-depth=1 -x /home
276M /home/kashif 276M /home/
Here the ‘du’ command shows the sizes of the ‘/’ and ‘home’ directories respectively. In order to get the right output we need to provide the complete patch of the directory for what we need to get the disk usage.
lsblk (list block):
This command can be used to list information about the block devices such as the number of attached hard drives and their mount point with its total size on your system.
Here are a few usage examples:
$ lsblk
To get more detailed information about block devices, including their mount points and sizes, use the -f option.
$ lsblk -f
The -t option produces a tree-like output that displays the relationships between devices and their partitions.
$ lsblk -t
These examples showcase various ways of using ‘lsblk’ command to list and display information about Linux block devices.
fdisk (fixed disk):
This is another command line tool to display and manipulate disk partition tables.
Let’s run the command below to check the disk size of your system.
$ fdisk
$ fdisk -l
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 100G 0 disk ├─sda1 8:1 0 512M 0 part /boot/efi └─sda2 8:2 0 99,5G 0 part / sr0 11:0 1 1024M 0 rom
When we run with ‘-l’ , it provides a detailed output showing information about disks, their sizes, types, and the partition layout, which includes details like start and end sectors, partition types, and file system information.
This command is very useful for understanding the disk structure and partitioning scheme of the Linux system.
parted :
This command line utility is an alternative of fdisk which is more user friendly and can be used to manipulate disk partitions of a Linux based system.
We can make use of this command line utility along with its list argument to get the disk usage information.
$ parted -l
Model: ATA VBOX HARDDISK (scsi) Disk /dev/sda: 107GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 538MB 537MB fat32 EFI System Partition boot, esp 2 538MB 107GB 107GB ext4
This is showing the more detailed information about the file system size and its type. It allows users to create, delete, resize, move, and manipulate disk partitions on various storage devices like hard drives and SSDs.
Conclusion:
In summary, Linux offers a range of commands like df, du, lsblk, and more to easily check remaining disk space. These tools provide quick insights into storage usage, helping users efficiently manage their systems and optimize storage allocation for better performance.