Special offer
.com Domain Name
English
+370 5 205 5502 sales@monovm.com

In this article we will go through some quick commands to clear disk space from your CentOS server.

25

Apr, 19

Disk Cleanup Methods in CentOS

Disk cleanup in CentOS

In this article we will go through some quick commands to clear disk space from your CentOS server. Before we go further, we will need to install the yum-utils package.

yum -y install yum-utils

  • Cleanup YUM cache

yum clean all

This is a simple command to cleanup the yum caches but this will not remove everything relating to yum.

In order to free up space by orphaned data from removed or disabled repositories we can use the following command:

rm -rf /var/cache/yum

In order to remove the user-cache which is created when the yum command is run through a regular user (without sudo) then we use this command:

rm -rf /var/tmp/yum-*

  • Removing old kernels

The following command keeps just the latest 2 kernels installed.

package-cleanup --oldkernels --count=2

  • Trim log files

The following code will shorten *.log files in the volume /var that are greater than 50M and older than 7 days or older than 30 days.

find /var -name "*.log" \( \( -size +50M -mtime +7 \) -o -mtime +30 \) -exec truncate {} --size 0 \;

  • Remove orphan packages

First you will need to check the existing orphan packages on your server.

package-cleanup --quiet --leaves --exclude-bin

If your satisfied with the results the continue in removing the orphan packages by running the following command.

package-cleanup --quiet --leaves --exclude-bin | xargs yum remove -y

  • Remove Node.js caches

rm -rf /root/.npm /home/*/.npm /root/.node-gyp /home/*/.node-gyp /tmp/npm-*

  • Remove composer cache

rm -rf /root/.composer/cache

rm -rf /home/*/.composer/cache

  • Remove core dumps

If you encountered severe failures with PHP which caused it to segfault and core dumps were enabled, then there is a high possibility that there are a few of those in your server. They are no longer needed after you debug the problem, so the following command will remove the files:

find -regex ".*/core\.[0-9]+$" -delete

 

Susith Nonis

I always had a passion for computers and how it works always fascinated me. I love to reasearch and share the knowledge with others in the simplest way possible.

user monovm

MiT

2019, Sep, 19

Nice article, thanks