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

table of contents
Hello, good evening
This is Miyazaki from the System Solutions Department.
In this article, I will explain how to check the disk capacity, how to organize the disk capacity,
I would like to write about the du and df commands that can be used in situations like these, with some examples
df command
df - Shows how much disk space is in use and how much is available
In actual work, the only option that is used is the -h option
-h, --human-readable
a size letter to each size, e.g., M for megabytes
. Use powers of 2 instead of powers of 10, so M
represents 1,048,576 bytes.
Here is the result of actually typing the command:
[root@localhost ~]# df -h Filesystem Size Used Remaining Used% Mounted on /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
We were able to check the disk capacity for each file system.
When checking disk capacity, it is easier to run this command first.
du command
du - command to display disk usage of files
The three options that are commonly used in actual work are -c, -h, and -s
-c, --total
Display the total amount
-h, --human-readable
Display sizes in human readable format (e.g. 1K 234M 2G)
-s, --summarize
Display only the total capacity of each argument
Here is the result of actually typing 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 run the du command on a directory with a capacity of several tens of gigabytes,
By investigating and specifying the directory that is taking up space, you can dig deeper and
find out which files in which directories are taking up space.
Next, we will examine the large directories individually
If you want to dig deeper into the directories under /usr, go to /usr and then run the command in the same way.
*You don't have to go there. You can also specify /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 we can see that the capacity under /usr/share is 1.3G
If you are having trouble searching because the data is too large or it takes too long to get the results,
--exclude=directories to exclude
By adding this option, you can exclude the target directory from the search.
Using the previous command as an example, the result is as follows.
[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 size excluding /usr/share
is displayed as 2.3G.
summary
What did you think?
Disk capacity increases day by day, and it often happens that you suddenly realize it's full.
I hope this article will be helpful in such situations. That's all.
4