Handling Windows system C drive full / Linux system disk block and inode full

Published: 2014-12-04

```html

Windows system

    Log in to the server remotely, downloadc盘清理.bat, save it to D:\ , double-click the bat file and it will automatically clean. It is recommended to set a scheduled task to clean regularly at 1:00 every night 

Run under cmd on Windows 2008 system:

schtasks /create /tn "cleanC" /tr D:\c盘清理.bat /sc daily /st 01:00:00


Linux system

     First log in to the server remotely via ssh. Login tutorial:http://www.west.cn/faq/list.asp?unid=417,

     A full disk falls into two cases. Then execute the following two commands respectively to see which case you belong to


Disk block is full, check command: df  -vh

blob.png

Disk inode is full, check command: df  -ih

blob.png

1. Handling method when block is full

Commands needed are as follows:

ll List files in the current directory

df –vh  View disk usage

cd directory name enter a directory

du -sh *  Count file size in the current directory

rm -rf file name|directory  delete a file or directory (the operation is irreversible; before deleting, please confirm whether the file is useless)


ls -A | grep -Ev 'home' |xargs du -sh Count file sizes of directories other than the home directory


1). Use df -vh to check which partition is full

blob.png

2). Use the cd and du commands to check which directory is the largest

blob.png

3). Continue executing the cd and du commands to find the largest file or directory

blob.png

4). Find the largest file and delete it with the rm -rf file name command

blob.png



PS: Before deleting, please confirm whether the files are useless, and delete only after confirmation. If all files are useful, please consider upgrading the disk size. If the cd command reports an error, please check whether what you entered is a directory. Use the ll command to check: directory names are blue and file names are white. In addition, if the du command has no response for a long time, please press Ctrl + C to end the command, execute the ll command, enter the next-level directory under the directory last displayed by the du command, and continue searching


2. Handling method when inode is full

Commands and scripts needed are as follows:

ll List files in the current directory

df –ih  View disk Inode usage

cd directory name enter a directory

du -ah *  Count file sizes in the current directory and subdirectories

rm -rf  file name|directory  delete a file or directory (the operation is irreversible; before deleting, please confirm whether the file is useless)

ls |xargs rm -rf  Delete all files in the current directory

check_inode_counts.pl script quickly counts the Inode size occupied by each directory under the directory

find */ ! -type l | cut -d / -f 1 | uniq -c  Count the Inode size occupied by each directory under the current directory (slow to execute; this command is not used by default)


1). Use df -ih to check which partition is full

blob.png

2) Download the check_inode_counts.pl script and execute it. Execute the following commands in order:

  wget http://downinfo.myhostadmin.net/check_inode_counts.txt

   mv check_inode_counts.txt check_inode_counts.pl

   perl check_inode_counts.pl /

   Continue executing for directories equal to 50000. If there are none, it means the directory with the maximum value has high usage. For example, if perl check_inode_counts.pl / shows that the /home directory equals 50000, continue executing perl check_inode_counts.pl /home, executing directory level by directory level to find the maximum usage, as shown in the figure

1.png


3). Continue searching, until you find the directory/directories with relatively large inode usage. Note that there are usually multiple directories.

After executing the ll command, many similar files will appear

blob.png

4). Use the cat file name command to check whether the file is abnormal. If abnormal, delete it; if not abnormal, continue searching

blob.png

Delete all abnormal files under this directory

blob.png


PS: If all files in the current directory are normal, please execute cd ../ to return to the upper-level directory and continue searching using the above method. Before deleting, please confirm whether the files are useless, and delete only after confirmation. If all files are useful, please consider upgrading the disk size. In addition, if the above deletion command hangs, you can use the find . -name "*.html"|xargs -t -n5 rm -rf command, where "*.html" is the suffix of the abnormal files seen above


Note: Before deleting files, please confirm whether the files are useless. If unsure, please consult the website programmer. In addition, the above methods only find and handle the problem. You need to analyze the cause yourself. If it is backups or logs that are full, you need to modify or close backups or logs. If a Trojan program has generated a large number of files, in addition to deleting the files, you also need to find the program vulnerability and fix it!

```