howtouselinux

2 ways to Check Disk space usage in Linux

Table of Contents

 

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.

Check disk space usage with df command in Linux

df command can be used to show disk usage.

we can use df command to display information about total space and available space on a file system. The FileSystem parameter specifies the name of the device on which the file system resides, the directory on which the file system is mounted, or the relative path name of a file system.

Normally, the df command uses free counts contained in the superblock. Under certain exceptional conditions, these counts might be in error. For example, if a file system is being actively modified when the df command is running, the free count might not be accurate.

  • 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 usage for file or directory with du command in Linux

du command, short for disk usage, is used to estimate file space usage. The du command can be used to track the files and directories which are consuming excessive amount of space on hard disk drive.

# 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 file or directories take up this space with du command. Then we need to remove some unwanted files to release the space or move the large files to other disks.

check disk performance in Linux with iostat command

Disk performance can be a tricky thing to optimize, especially on Linux systems. In this blog post, we will discuss three different ways to check disk performance in Linux. This is a handy trick to know if you are experiencing slowdowns or if you want to optimize your disk performance. We will be using the “iostat” command, the “iotop” command, and the “dd” command to check our disk performance.

The iostat command is a great way to see your current disk utilization. You can use the following syntax to run iostat: iostat -x /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

3 Ways to find largest files in Linux

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. More details here about disk utilization.

# 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

Iostat options

  • iostat: Get report and statistic.
  • iostat -x: Show more details statistics information.
  • iostat -c: Show only the cpu statistic.
  • iostat -d: Display only the device report.
  • iostat -xd: Show extended I/O statistic for device only.
  • iostat -k: Capture the statistics in kilobytes or megabytes.
  • iostat -k 2 3: Display cpu and device statistics with delay.
  • iostat -j ID mmcbkl0 sda6 -x -m 2 2: Display persistent device name statistics.
  • iostat -p: Display statistics for block devices.

Related Post:

4 Ways to Check Disk Partition with Examples in Linux

How to fix No space left on device issue on Linux

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Liquid Web Managed Word Press