{"id":57649,"date":"2020-10-07T10:32:33","date_gmt":"2020-10-07T15:32:33","guid":{"rendered":"https:\/\/blog.cpanel.com\/?p=57649"},"modified":"2020-10-07T10:32:33","modified_gmt":"2020-10-07T15:32:33","slug":"server-housekeeping-with-cpanel","status":"publish","type":"post","link":"https:\/\/devel.www.cpanel.net\/blog\/tips-and-tricks\/server-housekeeping-with-cpanel\/","title":{"rendered":"Server Housekeeping with cPanel"},"content":{"rendered":"\n
Servers are your virtual home and, just like your real home, they can become cluttered with unwanted junk. In the case of servers, it\u2019s not trash but data you have to kick to the curb every once in a while. <\/p>\n\n\n\n
Without a regular clear out, data accumulates until it fills the server\u2019s storage devices. Servers need to be able to write data to their hard drives. When there\u2019s no space to store new stuff, the performance takes a hit and some software will stop working altogether. <\/p>\n\n\n\n
We recommend that you keep at least 10 percent of the server\u2019s storage free, which means you will occasionally have to check disk space and find unused data to delete. In this article, we show you how to do just that with cPanel and the disk management tools on your Linux\u00ae server. <\/p>\n\n\n\n
There are a couple of prerequisites you should know about before we explain how to manage hard drive space. <\/p>\n\n\n\n
When you\u2019re concerned about disk space, WHM\u2019s Disk Usage<\/em> tool should be your first destination. It checks Linux disk space and displays the results in an intuitive interface. You will find it under System Health <\/em>in the WHM sidebar menu. <\/p>\n\n\n\n Disk Usage<\/em> shows a list of storage devices, their sizes, and how full they are. The number of devices and their names differ depending on the configuration of the server, but if they are more than 90% full, you should delete old data. <\/p>\n\n\n\n In the above image, we see that one of the hard drives on this server is dangerously full. To find out which files are causing the problem, we log in with SSH and use the command line to investigate. <\/p>\n\n\n\n First, we\u2019ll use the df <\/em>tool to check disk space on the server\u2019s hard drives. It provides more or less the same information as Disk Usage<\/em>, but it\u2019s helpful if you want to start your investigation on the command line instead of in WHM.<\/p>\n\n\n\n Run the command:<\/p>\n\n\n\n The -h flag tells df<\/em> to use human-readable units instead of spitting out confusing byte counts. The output looks something like this:<\/p>\n\n\n\n You can ignore the tmpfs<\/em> devices; they\u2019re virtual disks stored in memory and may not be present on your server. We\u2019ve underlined the interesting entry: the disk named \/dev\/vda1<\/em>, which is mounted on the root (\/) of the filesystem, <\/em>is 92 percent full. <\/p>\n\n\n\n Now we have verified that a disk is nearly full, we have to find out which files are responsible. For that, we use du<\/em>:<\/p>\n\n\n\n The -s option produces a summary of the data so we can more easily identify large files and directories. As before, -h tells du<\/em> to output sensible units. <\/p>\n\n\n\n At the end of the command is a file argument. In the last step, we found the overfull drive was mounted on \u201c\/\u201d, so that\u2019s where we start our search. The * means everything inside the \/ directory. <\/p>\n\n\n\n Here\u2019s a section of the output from du. <\/em><\/p>\n\n\n\n As you can see, the \/var directory consumes 40 GB, dwarfing the amount of data in the other directories. So, we run du <\/em>again on \/var. <\/em><\/p>\n\n\n\n <\/em>It\u2019s difficult to spot the largest files when there are lots of them, so we\u2019ll use sort<\/em><\/a> to print big files first and head<\/em><\/a> to grab the top 10. <\/p>\n\n\n\n We\u2019ve found the culprit! There is an enormous 39GB file in \/var. <\/p>\n\n\n\n Now we have to decide whether we can safely delete it or not. Deleting a file is irreversible, so you should do some research to verify that it doesn\u2019t contain data that matters to your or the server. <\/p>\n\n\n\n We know that it\u2019s safe to remove \/var\/largefile.log, <\/em>so we can delete it with the rm <\/em>command:<\/p>\n\n\n\n If you want to delete a directory of files, use this command instead:<\/p>\n\n\n\n The -f option means \u201cforce\u201d. It tells rm <\/em>to delete files without asking permission first. The -r option means \u201crecursive,\u201d and it makes rm <\/em>delete everything inside a directory. <\/p>\n\n\n\n If we go back to WHM\u2019s Disk Usage <\/em>page, we see that the device is no longer full, and the problems caused by the lack of storage space have been resolved. <\/p>\n\n\n\n Disk space problems are rarely caused by a single large file. In reality, you\u2019ll be dealing with lots of smaller files, but you can use the same process of identification and deletion with cPanel and the command line to find and remove any quantity of unwanted data. <\/p>\n\n\n\n As always, if you have any feedback or comments, please let us know. We are here to help in the best ways we can. You\u2019ll find us on Discord<\/a>, the cPanel forums<\/a>, and Reddit<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":" How to Check for Disk Space in Linux Servers are your virtual home and, just like your real home, they can become cluttered with unwanted junk. In the case of servers, it\u2019s not trash but data you have to kick to the curb every once in a while. Without a regular clear out, data accumulates […]<\/p>\n","protected":false},"author":77,"featured_media":65537,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[61],"tags":[],"class_list":["post-57649","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips-and-tricks"],"acf":[],"yoast_head":"\n<\/figure>\n\n\n\n
Check Disk Command<\/strong><\/h2>\n\n\n\n
df -h<\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n
du -sh \/*<\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n
du -sh \/var\/* | sort -rh | head -n 10<\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n
rm -f \/var\/largefile.log<\/code><\/pre>\n\n\n\n
rm -rf \/var\/largedirectory<\/code><\/pre>\n\n\n\n
<\/figure>\n\n\n\n