How to check disk space is a commonly asked question during a Linux job interview.
Disk space usage and disk utilization are different in Linux. Disk space usage means how much percent of space we use on the disk.
Disk utilization means how busy the disk is when there is some workload on it.
Today we will look at more details about this.
Boost Your Website Speed!
If you want your website to run as fast as ours, consider trying Cloudways. Their powerful cloud infrastructure and optimized stack deliver exceptional performance. Free migration!Table of Contents
Check disk space with df command in Linux
We can easily use df command to display information about total disk space and available disk space in Linux.
This command is especially useful for monitoring disk capacity and growth over time.
When running the df command, it will display all mounted drives, mount points, and total size of each drive along with the amount of available space on each drive.
This can help administrators determine if any disk or disk partitions are becoming full and need to be expanded or moved to a larger drive.
- Filesystem The name of the disk partition.
- Size The total size of the file system.
- used The total amount of space allocated to existing files in the file system.
- Available The total amount of space available within the file system.
- Percentage used The percentage of the available space that currently allocated to all files on the file system.
- Mounted on The directory in which the file system appears.
Df command Options
- df -h shows disk space in human-readable format
- df -a shows the file system’s complete disk usage even if the Available field is 0
- df -T shows the disk usage along with each block’s filesystem type (e.g., xfs, ext2, ext3, btrfs, etc.)
- df -i shows used and free inodes
- df -t, –type=TYPE : limit listing to file systems of type TYPE
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/wbx_vg-root 20G 1.8G 18G 9% /
/dev/mapper/wbx_vg-opt 9.8G 217M 9.6G 3% /opt
/dev/mapper/wbx_vg-tmp 4.9G 45M 4.9G 1% /tmp
/dev/mapper/wbx_vg-u00 43G 20G 24G 46% /u00
/dev/mapper/wbx_vg-var 9.8G 757M 9.1G 8% /var
/dev/mapper/wbx_vg-var_crash 33G 39M 33G 1% /var/crash
/dev/sdo1 509M 159M 350M 32% /boot
Check disk space for file or directory with du command in Linux
du command, short for disk usage, is used to estimate file space usage. It is a commonly used command line tool that calculates the amount of disk space used by files and directories.
We can use this command to get a better understanding of which directories were taking up the most space on the disk. This information was helpful in determining which directories needed to be optimized or cleaned up.
# du -h /home/howtouselinux/test
Output:
44K /home/howtouselinux/test/data
2.0M /home/howtouselinux/test/system design
24K /home/howtouselinux/test/table/sample_table/tree
Difference between df and du in Linux
- df – check disk space
- du – check disk space for file or directory
- df is a standard Linux command used to display the amount of available disk space for file systems.
- du is a standard Linux command used to estimate file space usage—space used under a particular directory or files on a file system. The du command summarizes disk space used for each FILE and/or directory.
How to fix disk space issue in Linux?
We can get how much percent space we already used on the disk or disk partition from df command Use% column. If it is over 80%, we should check which files take up this space with du command.
Then we need to remove some files to release the space or move the large files to other disks.
FAQ about disk command in Linux
check disk performance in Linux with iostat command
Disk performance can be a tricky thing to optimize, especially on Linux systems. The iostat command is a great way to see your current disk utilization. You can use the following syntax to run iostat: iostat -xk /dev/sda
This will print out a report of your disk activity, including the amount of read and write operations, the average response time etc.
Check which process using the most disk io in Linux with iotop command
The iotop command is another great way to see what processes are using the most disk I/O. You can use the following syntax to run iotop: iotop -aoP
This will print out a report of the processes that are using the most disk I/O, along with the percentage of disk I/O each process is using. You can then use this information to determine which processes are causing slowdowns.
Check disk performance with dd command in Linux
The dd command is a great way to check the read and write speed of your disk. You can use the following syntax to run dd: dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync
This will create a file called “test” that is 64KB in size and will write zeros to it. This is a good way to test the write speed of your disk. To test the read speed, you can use the following syntax: dd if=test of=/dev/null bs=64k count=16k
How to check disk utilization on Linux?
Iostat command can be used to show disk utilization. We can get how busy our disk is when there is some workload on it from column %util. If it is over 80%, we need to check the workload like iops, io size or storage latency to fix it.
# iostat -kx 3 /dev/sdo
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sdo 0.06 0.78 1.62 13.27 98.69 177.04 37.04 0.50 33.48 72.83 28.68 4.21 6.27
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sdo 0.00 0.00 0.00 12.00 0.00 82.50 13.75 0.18 15.22 0.00 15.22 4.56 5.47
Related Post: