How to Clear Disk Space on CentOS 6 or CentOS 7

How to Clear Disk Space on CentOS 6 or CentOS 7

Following are the quick commands to clear disk space on your CentOS 6 or CentOS 7 server.

First you need to install the yum-utils package:

yum -y install yum-utils

1. Prune log files

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

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

2. Clean up the YUM cache

Cleaning the yum cache is simple:

yum clean all

Please note that the above command will not remove all the files associated with yum that have been installed.

You may want to free up space occupied by orphaned data in disabled or deleted repositories:

rm -rf /var/cache/yum

Also, when you accidentally yum through a normal user (forget sudo), yum will create a user cache. So we remove that as well:

rm -rf /var/tmp/yum-*

3. Delete orphan packages

Check for existing orphan packages

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

Confirm deletion of orphaned packages

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

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

4. Delete WP CLI cached WordPress downloads

Every time you set up a new WordPress site, WP CLI saves a WordPress archive. You can delete these caches with the following command:

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

5. Delete the old kernel

Before removing the old kernel, you may want to reboot first so that you can boot from the latest kernel.

Because you can't remove old kernels from the current boot system 🙂

The following command will keep only the 2 most recent kernels:

package-cleanup --oldkernels --count=2

Note that with some VPS providers (such as Linode), the server defaults to using a kernel built by the provider, rather than the server's own kernel. Therefore, it makes no sense to keep more than 1 old kernel on your system. so:

package-cleanup --oldkernels --count=1

6. Delete Composer Cache

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

7. Delete core dumps

If you have some serious PHP glitch that causes it to segfault and enable core dumps, then chances are - you have a lot of them.
They are not needed once you are done debugging the problem. so:

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

8. Delete the error_log file (cPanel)

If you use a nasty cPanel, you will surely have dozens of error_log files scattered throughout your web directory. If you can install Citrus Stack, that's much better. A temporary solution is to delete all of these files:

find /home/*/public_html/ -name error_log -delete

9. Delete Node.js cache

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

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of Centos7 disk space expansion (LVM management)

<<:  JavaScript implements simple date effects

>>:  MySQL daily statistics report fills in 0 if there is no data on that day

Recommend

Example of how to enable Brotli compression algorithm for Nginx

Brotli is a new data format that can provide a co...

A brief discussion on the use of Web Storage API

Table of contents 1. Browser local storage techno...

Div css naming standards css class naming rules (in line with SEO standards)

There are many tasks to be done in search engine o...

Vue implements adding watermark to uploaded pictures

This article shares the specific implementation c...

How to set up virtual directories and configure virtual paths in Tomcat 7.0

Tomcat7.0 sets virtual directory (1) Currently, o...

Simple Mysql backup BAT script sharing under Windows

Preface This article introduces a simple BAT scri...

VUE introduces the implementation of using G2 charts

Table of contents About G2 Chart use Complete cod...

A comparison between the href attribute and onclick event of the a tag

First of all, let's talk about the execution ...

Detailed explanation of keepAlive use cases in Vue

In development, it is often necessary to cache th...

HTML table cross-row and cross-column operations (rowspan, colspan)

Generally, the colspan attribute of the <td>...

What command is better for fuzzy searching files in Linux?

1. Introduction This article mainly explains how ...

Complete code for implementing the vue backtop component

Effect: Code: <template> <div class=&quo...

Centos7 mysql database installation and configuration tutorial

1. System environment The system version after yu...

Summary of 7 types of logs in MySQL

There are the following log files in MySQL: 1: re...

Let's take a look at some powerful operators in JavaScript

Table of contents Preface 1. Null coalescing oper...