Inodes Describes how file data is stored in blocks in Linux. File meta-information, such as file creator, file creation date, and file size, is displayed. The area where the meta information is stored is called an inode, or “index node” in Chinese. The inode also occupies space on the hard disk, and when the hard disk is formatted, the operating system automatically divides the hard disk into two areas. One is the data area, storing file data; The other is the inode table, which stores the information contained in the inode.

The size of each inode node, typically 128 or 256 bytes. The total number of inode nodes, given at formatting time, is typically one inode per 1KB or 2KB. Assuming a 1GB hard disk with 128 bytes for each inode node and one inode for every 1KB, the size of the inode table would be 128MB, or 12.8% of the total hard disk.

Inodes resource Used up Similar to that of the storage space used up, files cannot be created or commands cannot be executed. When the inodes are used up, the inode table can be filled with a large number of small files.

In most cases, only a few percent of the storage space is used up, so it is easy to ignore the monitoring of inodes usage.

To display the usage of disk space, run the df command to view the usage of disk space



To check the usage of inodess, run the df -i command

The preceding two commands can use the -h parameter. The commands are df -h and df -hi. You can see that disk space is 71% used, but inodes is 100% used.

The inodes size is determined when the disk is formatted as a partition. The larger the partition, the larger the inodes are, and vice versa.

In Linux, the partition of the root directory is small. If periodic small files are generated and the inodes are not cleared in time, the inodes may be used up.

Inodes are full.

1. View the directory with the most files

for i in /*; do echo $i; find $i | wc -l; done
Copy the code

If the directory scope is specified, make the /* more specific

Eventually found is/var/spool/postfix/maildrop directory too small file, here’s why: because the Linux in execute cron, cron script execution will be the output and warning information, will be in the form of mail sent to the cron owner. Because sendmail and Postfix in the customer environment did not work properly, the mail could not be sent successfully, and all the small files were piled up in the MailDrop directory. Moreover, due to the lack of automatic cleaning mechanism, a large number of files were piled up in this directory.

The root user has delivered a scheduled clock synchronization task that generates a small file every minute.

2. Delete a large number of files

Ls | xargs - n 1000 rm - rf # need to use xargs command, or it will delete failed.Copy the code

If you add MAILTO=”” to the first line of crontab -e, no file will be generated

2. Redirection The output file of scheduled tasks can be redirected to /dev/null for scheduled tasks that do not require log output, as follows:

*/10 * * * * /tmp/test.sh >/dev/null 2>&1
Copy the code

3. Clean files regularly

Find directories -type f - mtime + 30 | xargs -n 1000 rm -f * *Copy the code

4. Monitor inodes usage

Note: Pay attention to the format of crontab and the periodic clearing of generated files