How to clean up disk space in CentOS

from: https://www.getpagespeed.com/server-setup/clear-disk-space-centos

Quick commands to clear disk space on CentOS 6 server.
Before anything, you have to install yum-utils package.

1. Trim log files

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

This will truncate any *.log files on the volume /var that are either older than 7 days and greater than 50M or older than 30 days.

2. Cleanup YUM cache

Simple command to cleanup yum caches:

yum clean all

Note that the above command will not remove everything always.
So you may want to do the harsh thing and remove caches directory directly:

rm -rf /var/cache/yum

Also, when you accidently run yum via regular user (forgot sudo), yum will create user-cache. So let’s delete that too:

rm -rf /var/tmp/yum-*

3. Remove orphan packages

Check existing orphan packages

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

Confirm removing orphan packages

Now, if happy with suggestions given by previous command, run:

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

(Note: if the system complains package-cleanup not found, then you need to install yum-utils)

4. Remove WP CLI cached WordPress downloads

WP CLI saves WordPress archives every time you setup a new WordPress website. You can remove those caches by the following command

rm -rf /root/.wp-cli/cache/*
rm -rf /home/*/.wp-cli/cache/*

5. Remove old kernels

The following command will keep just 2 latest kernels installed:

package-cleanup --oldkernels --count=2

Note that with some VPS providers (Linode for example), servers use provider’s built kernels by default and not the ones on the server itself. So it makes little sense to keep more than 1 old kernel on the system. So:

package-cleanup --oldkernels --count=1

6. Remove Composer cache

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s