How to check Disk Usage

Checking whether the root partition has run out of inodes. Use the command. If it shows 100%, there are many small files. Perhaps, do look for some of these files at /tmp

df -i
Filesystem                                      Inodes        IUsed        IFree IUse% Mounted on
/dev/mapper/centos-root                        9788840       320849      9467991    4% /
devtmpfs                                      70101496          560     70100936    1% /dev
tmpfs                                         70105725            8     70105717    1% /dev/shm
tmpfs                                         70105725         1581     70104144    1% /run
.....
.....

You may want to check which directories is using the most space with the commands below

% du -hx -d 1 |sort -h
1.3M    ./Espresso-BEEF
4.9M    ./NB07
8.3M    ./Gaussian2
31M     ./Gaussian
65M     ./MATLAB
478M    ./Abaqus
647M    ./pytorch-GAN
10G     ./COMSOL
12G     .

-h argument produces the human-readable output
-x restricts the search to the current directory
-d 1 is the summary for each directory
sort -h produces human-readable output and the directories with the largest usage will appear at the bottom of the list.

Checking Disk Usage within the subfolders but avoid mount-point

If you need to check Usage, but you wish to avoid the mount-point, you can use the command

[root@hpc-hn /]# du -h -x -d 1
48M     ./etc
552M    ./root
11G     ./var
1.1G    ./tmp
11G     ./usr
0       ./media
0       ./mnt
4.8G    ./opt
0       ./srv
0       ./install
0       ./log
0       ./misc
0       ./net
0       ./server_priv
0       ./ProjectSpace
0       ./media1
0       ./media2
28G     .
  • -h refers to human-readable
  • -d refers to depth level. By default, it is 0 which is the same as summarize
  • -x skip directories on different file systems

Checking Disk Usage Examples

Point 1: To check and list disk usage of /var/log directory is given below

# du -hx /var/log --max-depth=1
0 /var/log/ntpstats
57M /var/log/sa
288K /var/log/tuned
39M /var/log/audit
0 /var/log/chrony
112K /var/log/xcat
3.2M /var/log/anaconda
0 /var/log/rhsm
12K /var/log/Lenovo_Support

Point 2: Sort out and list disk usage in /var/log is given below

# du -hx /var/log --max-depth=1 |sort -h
0 /var/log/chrony
0 /var/log/ntpstats
0 /var/log/rhsm
12K /var/log/Lenovo_Support
112K /var/log/xcat
288K /var/log/tuned
3.2M /var/log/anaconda
39M /var/log/audit
57M /var/log/sa
108M /var/log

Point 3: Show last modification time and sort it by usage

# du -hx /var/log -d 1 --time -a --max-depth=1 |sort -h
0 2017-04-13 05:24 /var/log/ntpstats
0 2017-08-04 05:27 /var/log/chrony
0 2018-03-30 03:21 /var/log/tallylog
0 2018-03-30 03:27 /var/log/rhsm
0 2018-03-30 06:21 /var/log/opensm-activity.dump
0 2019-05-07 18:39 /var/log/opensm.log
0 2019-09-30 03:36 /var/log/spooler-20191006
0 2019-10-01 03:17 /var/log/btmp-20191101
0 2019-10-06 03:41 /var/log/spooler-20191013
0 2019-10-13 03:43 /var/log/maillog-20191021
0 2019-10-13 03:43 /var/log/spooler-20191021
0 2019-10-21 03:28 /var/log/maillog-20191027
0 2019-10-21 03:28 /var/log/spooler-20191027
0 2019-10-24 03:30 /var/log/boot.log-20191024
0 2019-10-25 03:30 /var/log/boot.log-20191025
0 2019-10-26 03:11 /var/log/boot.log-20191026
0 2019-10-27 03:07 /var/log/boot.log-20191027
0 2019-10-27 03:07 /var/log/spooler
0 2019-10-28 03:48 /var/log/boot.log-20191028
0 2019-10-29 03:28 /var/log/boot.log-20191029
0 2019-11-01 10:29 /var/log/boot.log
0 2019-11-01 10:29 /var/log/boot.log-20191101
0 2019-11-01 10:29 /var/log/btmp
4.0K 2018-03-30 03:21 /var/log/grubby_prune_debug
4.0K 2018-03-30 05:08 /var/log/grubby
4.0K 2019-02-25 03:06 /var/log/opensm.log-20190225.gz
4.0K 2019-02-25 19:31 /var/log/opensm.log-20190303.gz
4.0K 2019-04-07 23:25 /var/log/opensm.log-20190408.gz
4.0K 2019-05-07 17:10 /var/log/opensm.log-20190507.gz
4.0K 2019-10-14 17:30 /var/log/secure-20191021
4.0K 2019-10-24 20:06 /var/log/yum.log
4.0K 2019-11-01 15:41 /var/log/secure
8.0K 2018-09-10 15:01 /var/log/centrifydc-install.log
8.0K 2019-10-02 12:02 /var/log/secure-20191006
8.0K 2019-10-24 22:24 /var/log/secure-20191027
8.0K 2019-11-01 15:30 /var/log/maillog
12K 2018-03-30 13:41 /var/log/Lenovo_Support
.....
.....
.....
39M 2019-10-29 06:00 /var/log/audit
57M 2019-11-01 16:20 /var/log/sa
108M 2019-11-01 16:20 /var/log