Blog

How to check disk utilization in Linux – 3 important commands

While using Linux as Server, you frequently need to check storage utilization. In that case, how do you know how much is the utilization, which directory is taking much space. Why is my server not responding? Why is my disk space full? who is taking all storage? To answer all these questions, you need to know the below 3 commands to check disk utilization in Linux

1. df

df command will show you which disk and mounts are at how much utilization

  • -h use -h tag to see results in human-readable format (MB/GB)

In the below example, my main volume is /dev/xvda1 which is 63% used, 4.9 GB is used and 2.9GB is available

make sure you have at least 5% free available storage space for the smooth functioning of your server

$df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.7G  4.9G  2.9G  63% /
  • -i use -i tag to see inodes utilization.

An inode is a file data structure that stores information about any Linux file except its name and data. It is like indexing of file structure of whole operating system

  • If inodes are full, that means file system can’t store any more files or directories because it can not index it. In that case, it might happen that you still have disk available but you can’t store anything
$df -i
ubuntu@ip-172-31-9-60:~$ df -i
Filesystem      Inodes  IUsed  IFree IUse% Mounted on
/dev/xvda1     1024000 223664 800336   22% /

2. ls -ah

ls -lah command will show you which file size

  • -h use -h tag to see results in human-readable format (MB/GB)
  • -a for hidden files
  • -l for a long list of file permission, creation/updatation dates and file sizes

In the below example, we have 2 files where one is having 117 B of data and another one is empty

$ ls -lah 
-rw-r--r--  1 root root  117 Jul 18 06:17 identicalcloud-file1
-rw-r--r--  1 root root    0 Jul 18 03:11 identicalcloud-file2

ls command will only show you filesizes and not directory ones.

3. du

du command will show you the directory’s disk usage. This command is very useful, You can run it at root level and it will help you find out which directory you should look into

du -sch *

4.0K    ic-dir2
8.0K    ic-dir3
4.0K    ic-dir4
16K     total
  • -h use -h tag to see results in human-readable format (MB/GB)
  • -s is used for summarize, so it will print total value
  • -c will in the end produce total for all directories size

Run this command in / directory to get values for whole filesystem’s usage

run this command as root user to get all information

$ cd / 
$ du -sch *
15M     bin
107M    boot
0       dev
6.0M    etc
60K     home
0       initrd.img
0       initrd.img.old
252M    lib
4.0K    lib64
16K     lost+found
4.0K    media
4.0K    mnt
16K     opt
0       proc
154M    root
872K    run
15M     sbin
1.3G    snap
4.0K    srv
0       sys
40K     tmp
2.2G    usr
2.3G    var
0       vmlinuz
0       vmlinuz.old
6.2G    total

In above example, it shows that var and usr directories have the highest usage i.e. 2.3 GB and 2.2 GB

As the next step, you can go inside those directories and check usage. For that run same command again

We hope you can find out important information about how to check disk utilization. Remember those commands, save this post to keep it handy.

Drafted On,
4th December 2021
DevOps @identicalCloud.com

Summary
How to check disk utilization in Linux - 3 important commands
Article Name
How to check disk utilization in Linux - 3 important commands
Description
Server space is full? checkout out these three commands which can show you exact utilization for your disk
Author
Publisher Name
IdenticalCloud
Publisher Logo

Leave a Comment