Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

What are the situations when disk space is full?

The first case is that the remaining block space is insufficient (df -h).

The disk inode is not enough (df -i)

No space left on device The block space is used up. The inode space is used up. A large number of small files are generated

Inode and blockde

Difference between inode and blockde:

Inode and blockde

Inode: (index node) Index node information Properties of a file or directory used to store data (file permission owning user owning group) Block: block Used to store data Real data information about a fileCopy the code

2. How did inode and blockde come into being?

Only after the disk is formatted and the file system is created will there be inodes and blocks to create a file that occupies at least one inode and one blockCopy the code

3. How can INOde and blockDE query corresponding information

Inode information: [root@VM-0-3-centos ~]# df -i
Filesystem      Inodes IUsed   IFree IUse% Mounted on
devtmpfs        232347   329  232018    1% /dev
tmpfs           235251     7  235244    1% /dev/shm
tmpfs           235251   422  234829    1% /run
tmpfs           235251    16  235235    1% /sys/fs/cgroup
/dev/vda1      3276800 81268 3195532    3% /
tmpfs           235251     1  235250    1% /run/user/0
Copy the code
To view block information, run the following command: [root@VM-0-3-centos ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        908M     0  908M   0% /dev
tmpfs           919M   24K  919M   1% /dev/shm
tmpfs           919M  476K  919M   1% /run
tmpfs           919M     0  919M   0% /sys/fs/cgroup
/dev/vda1        50G  3.5G   44G   8% /
tmpfs           184M     0  184M   0% /run/user/0
Copy the code

4, why is df -h and df -i used to display disk usage, but the two have such a big difference?

Df -h is used to delete large and useless files - large files occupy a large amount of disk capacity. Df -i removes too many small files - too many files occupy too many inode numbers. PS: If df checks that any disk space is full, delete the files in the file to clear the disk spaceCopy the code

(df -h) (df -h) (df -h)

Run the df -h command to check the disk capacity. It is found that /dev/vda1 has a large capacity

[root@VM-0-3-centos /]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        908M     0  908M   0% /dev
tmpfs           919M   24K  919M   1% /dev/shm
tmpfs           919M  468K  919M   1% /run
tmpfs           919M     0  919M   0% /sys/fs/cgroup
/dev/vda1        50G  3.5G   44G   8% /
tmpfs           184M     0  184M   0% /run/user/0
Copy the code

Go to the/(root) directory and run du -sh * to check the capacity of all directories in the/(root) directory

[root@VM-0-3-centos ~]# cd /
[root@VM-0-3-centos /]# du -sh *
0       bin
123M    boot
4.0K    data
0       dev
37M     etc
4.0K    home
0       lib
0       lib64
16K     lost+found
4.0K    media
4.0K    mnt
127M    opt
0       proc
72K     root
476K    run
0       sbin
4.0K    srv
0       sys
19M     tmp
2.7G    usr
408M    var
Copy the code

If the usr directory occupies large capacity, go to the usr directory and continue the du -sh * troubleshooting

[root@VM-0-3-centos /]# cd /usr
[root@VM-0-3-centos usr]# du -sh *
277M    bin
4.0K    etc
8.0K    ftp
4.0K    games
33M     include
774M    lib
345M    lib64
98M     libexec
504M    local
79M     mpi
55M     sbin
394M    share
184M    src
0       tmp
Copy the code

Go to the directory SRC that occupies a large capacity to check the capacity

[root@VM-0-3-centos usr]# cd src
[root@VM-0-3-centos src]# du -sh *
8.8M    debug
77M     kernels
8.0K    mlnx-ofa_kernel
4.0K    mulu
62M     ofa_kernel
37M     ofa_kernel-5.1
4.0K    wenjian
Copy the code

PS: This operation is to simulate the situation that directories or files are very large and need to be cleaned up. At this time, we can check which files occupy large memory. We take the mulu(directory) and wenjian (file) that I simulated to create as test objects. Clear the files in /usr/src/mulu.

[root@VM-0-3-centos src]# rm -r /usr/src/mulu/*Rm: remove the directory '/ usr/SRC/mulu/fu'? yCopy the code

2. Clean up/usr/SRC/wenjian wenjian files under the SRC directory of using redirects command to empty the contents of the file (there are other ways to empty the contents of the file is not a demo)

[root@VM-0-3-centos src]# echo " " >> /usr/src/wenjian
Copy the code

(df-ih); (df-ih)

And the reason why we add h is because it’s a direct output and people can see the units of capacity directly

Run the df-ih command to check the inode. The inode usage in the root directory is 100%

[root@VM-0-3-centos ~]# df -ih
Filesystem     Inodes IUsed IFree IUse% Mounted on
devtmpfs         227K   329  227K    1% /dev
tmpfs            230K     7  230K    1% /dev/shm
tmpfs            230K   420  230K    1% /run
tmpfs            230K    16  230K    1% /sys/fs/cgroup
/dev/vda1        3.2M   3.2M  0      100% /
tmpfs            230K     1  230K    1% /run/user/0
Copy the code

Solution: Run the following command to view larger directories

[root@VM-0-3-centos ~]# find / -xdev -printf '%h\n' | sort | uniq -c | sort -k 1 -n
Copy the code

If you find a directory that contains more small files, go to the directory that contains more small files and delete small files. Run the following command: CD Go to the /xx/xx/xx directory, filter files in the directory and delete them

[root@VM-0-3-centos ~]# cd /xx/xx/xx && find -type f |xargs rm -f
Copy the code