[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, 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.