[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

[Linux] How to check disk capacity using du and df commands when you want to organize your disk

Hello, good evening.

This is Miyazaki from the System Solutions Department.

In this article, we will explain how to check your disk capacity and how to organize it because your disk capacity is tight.

I would like to write about the du command and df command, which are used in such cases, with examples.

df command

df - Display amount of disk in use and available

The only thing I use in actual work is the -h option.

-h, --human-readable

Add
a size letter, such as M for megabytes, to each size Since we use powers of 2 instead of powers of 10, M represents 1,048,576 bytes.

Here is the result of actually hitting the command.

[root@localhost ~]# df -h File system size Used Remaining Used % Mount location /dev/mapper/cl-root 6.2G 4.9G 1.4G 78% / devtmpfs 905M 0 905M 0% /dev tmpfs 920M 208K 920M 1% /dev/shm tmpfs 920M 8.7M 912M 1% /run tmpfs 920M 0 920M 0% /sys/fs/cgroup /dev/sda1 1014M 226M 789M 23% /boot tmpfs 184M 16K 184M 1% /run/user/1000

I was able to check the disk capacity for each file system.
When checking the disk capacity, I think it will be easier to understand if you run this command first.

du command

du - command to display disk usage of files

There are three options that are often used in actual work: -c, -h, and -s.

-c, --totalDisplay
the total amount

-h, --human-readableDisplay
sizes in human-readable format (e.g. 1K 234M 2G)

-s, --summarizeDisplay
only the total capacity of each argument

Here is the result of actually hitting the command.

 [root@localhost /]# du -sch ./* 0 ./1 0 ./bin 194M ./boot 156K ./dev 49M ./etc 4.6M ./home 0 ./lib 0 ./lib64 0 ./media 0 ./mnt 19M ./opt 0 ./proc 52K ./root 65M ./run 0 ./sbin 0 ./srv 0 ./sys 296K ./tmp 3.7G ./usr 1.1G ./var 5.0G Total

*Please note that if you actually use the du command on a directory with a capacity of several tens of gigabytes,
the I/Owait will increase for a long time.

If you look into it, specify the directory that is taking up space, and dig deeper,
you will be able to see which file in which directory is taking up space.

Next, we will examine individual directories that have a large amount of space.

If you want to dig deeper into the directories under /usr, move to /usr and issue the same commands.
*It is not necessary to move. You can also specify it as /usr/*.

 [root@localhost /]# cd /usr [root@localhost usr]# du -sch ./* 209M ./bin 0 ./etc 0 ./games 18M ./include 716M ./lib 1.2G ./lib64 102M . /libexec 4.0K ./local 57M ./sbin 1.3G ./share 109M ./src 0 ./tmp 3.7G total

This is just an example, but from this result you can see that the capacity under /usr/share is 1.3G.

If there is a problem that you cannot investigate because of the large capacity, or if it takes a long time to get the results.

--exclude=directory you want to exclude

By adding this option, you can exclude the target directory from being searched.
Using the previous command as an example, we get the following result:

 [root@localhost usr]# du -sch ./* --exclude=share 209M ./bin 0 ./etc 0 ./games 18M ./include 716M ./lib 1.1G ./lib64 102M ./libexec 0 ./ local 57M ./sbin 109M ./src 0 ./tmp 2.3G total

the /home/qmail directory is not searched and
the total excluding /usr/share is displayed as 2.3G.

summary

What did you think?
Disk capacity increases day by day, and there are many times when you realize it's full.
I hope this helps in times like these. That's it.

If you found this article helpful , please give it a like!
2
Loading...
2 votes, average: 1.00 / 12
26,606
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

The person who wrote this article

About the author

Kenta Miyazaki

I joined Beyond in 2017 as a new graduate.

We provide 24-hour, 365-day operation, maintenance, and monitoring services for servers and clouds used by companies that primarily provide web-based services.
I belong to the System Solutions Department, and my job is to improve Beyond's operations so that our customers can focus on their business.

Certifications: AWS Certified Solutions Architect, GCP Professional Cloud Architect, Linuc1