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

Clear Disk Space on CentOS 6, 7, 8

Disk cleanup in CentOS 6, 7, 8

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 an easy command to cleanup the yum caches but this may not remove everything concerning yum.

In order to free more space by orphaned data from removed or disabled repositories we will use the subsequent command:

rm -rf /var/cache/yum

In order to get rid of the user-cache which is made 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 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 subsequent 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'm fascinated by the IT world and how the 1's and 0's work. While I veture into the world of Technology I try to share what I know in the simplest way to you. Hope you like it.

user monovm

MiT

2019, Sep, 19

Nice article, thanks

user monovm

eShopping Nepal

2020, Oct, 20

Thank you for your blog post. I got about 1GB space from my server. Thanks

user monovm

susith nonis

2020, Oct, 20

We're glad it helped you ;)