📜 ⬆️ ⬇️

Something "steals" disk space?

If you do not follow the remaining free space in the root section, then you can expect unpleasant news. In case of overflow of this section, the services important for your project will stop working. Agree, a broken MySQL or web server will affect the project not in the best way.



One of the best solutions to this issue will be to use some utilities that will help you determine what the problem is, what exactly is taking up disk space. The moment when it is gradually filled, leads to difficulties in analyzing this problem. For this, there are a number of commands that will help you to monitor fairly quickly. Most often, the culprit of this problem is a “demon” , actively recording its actions in the log file (hello to people who do not set up a log rotation, or forget to turn off debug mode in services after debugging).

Search for the largest files
At such moments, the main task is to quickly find the necessary free space. The easiest method is to use df with du : #df -h will show the place by section; #du -sh / directory is the directory occupied (the -s switch removes extra output).
')
The most likely culprit is / var / log second in place / home / , then go / backup & / var / www / . In the case when the web-server log is to blame, it is enough to delete or clear the log file. Please note that in cases when the file is kept by the daemon ( apache log), it is worthwhile to pull apache to recalculate free space, you can reset the file with the following command # echo ''> /var/log/httpd/httpd.log

If you have some questions about the total amount of memory, then you can use the df -h command and find out the amount of free space in the file system. So, let's begin:

# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg0-root 53G 44G 6.2G 88% / tmpfs 939M 0 939M 0% /dev/shm /dev/vda1 485M 45M 415M 10% /boot /dev/mapper/vg0-temp 2.0G 75M 1.8G 4% /tmp 

A rare option is when df -h shows free 88% in a section, but file creation is not possible. In this case, it is worth using df with the -i key, the # df command called with this key will show the free inode value for the file system.

 # df -i Filesystem Inodes IUsed IFree IUse% Mounted on /dev/mapper/vg0-root 3506176 320241 3185935 10% / tmpfs 240295 1 240294 1% /dev/shm /dev/vda1 128016 44 127972 1% /boot /dev/mapper/vg0-temp 131072 275 130797 1% /tmp 

Adding the -l (local) key - you will see data only about locally-mounted file systems:

 # df -hl Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg0-root 53G 44G 6.2G 88% / tmpfs 939M 0 939M 0% /dev/shm /dev/vda1 485M 45M 415M 10% /boot /dev/mapper/vg0-temp 2.0G 75M 1.8G 4% /tmp 

Using the sort command, you sort the strings included in all source files. If the file names are not specified, or the file is specified as - , the original information comes from the standard input. Adding the option -n (numerical comparison) with which the leading spaces are first discarded, then numeric character strings, containing perhaps a minus sign and a decimal point, you get the following result:

 # df -hl | sort -n /dev/mapper/vg0-root 53G 45G 5.9G 89% / /dev/mapper/vg0-temp 2.0G 75M 1.8G 4% /tmp /dev/vda1 485M 45M 415M 10% /boot Filesystem Size Used Avail Use% Mounted on tmpfs 939M 0 939M 0% /dev/shm 

Using the du (disk used) utility, you get a report on the use of disk space by the specified files, as well as each directory of the subdirectory hierarchy of each specified directory. If you run the command with no arguments, du will report the disk space for the current directory.

 # du 8 ./.config/htop 12 ./.config 5056 ./.xmlcache/ispmgr/checked 15048 ./.xmlcache/ispmgr 752 ./.xmlcache/core/checked 4440 ./.xmlcache/core 1088 ./.xmlcache/ispmgrnode/checked 6780 ./.xmlcache/ispmgrnode 26284 ./.xmlcache 20 ./.ssh 168 ./.gem/specs/api.rubygems.org%443/quick/Marshal.4.8 172 ./.gem/specs/api.rubygems.org%443/quick 8376 ./.gem/specs/api.rubygems.org%443 8380 ./.gem/specs 8384 ./.gem 8 ./.spamassassin 4 ./.mc/cedit 32 ./.mc 12 ./mod 

By adding the - - time parameter , you will get a data output with the specified modification time.

 # du --time . | sort -k2 | tail -5 5056 2015-07-29 17:11 ./.xmlcache/ispmgr/checked 20 2015-09-03 18:04 ./.ssh 4 2015-10-15 12:42 ./test 32 2015-10-20 19:38 ./.mc 1245816 2015-11-06 13:50 . 

You can also search for large files using the find command :

 # find . -size +1M -ls | sort -n -k7 15089762 1264 -rw-r----- 1 shs staff 1289365 Feb 24 2015 ./bin/235.log 12731834 1724 -rw-r----- 1 shs staff 1761280 Oct 15 2015 ./bin.tar 13320206 2192 -rw------- 1 shs staff 2239058 Dec 8 2015 ./mail/lab7 13320203 6308 -rw------- 1 shs staff 6443348 Oct 26 2015 ./mail/lab6 12731744 19736 -rw-r----- 1 shs staff 20183040 Jul 29 2015 ./backup.tar 

A handy utility for a general assessment of the space occupied and cleaning up irrelevant data. Ncdu - provides a pseudo-graphic interface, and easy navigation. Of the minuses: not suitable for emergency situations described in the beginning of the article, because ncdu first counts the entire volume of files of the specified disk (directories), and only having collected the required information, it gives the result with which you can work.



PS We conduct a campaign specifically for Habr's readers. Post with the details here .

Source: https://habr.com/ru/post/271101/


All Articles