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

Nginx signal control

Introduction to Nginx Nginx is a high-performance...

Mysql online recovery of undo table space actual combat record

1 Mysql5.6 1.1 Related parameters MySQL 5.6 adds ...

A brief analysis of the usage of USING and HAVING in MySQL

This article uses examples to illustrate the usag...

How to deploy python crawler scripts on Linux and set up scheduled tasks

Last year, due to project needs, I wrote a crawle...

Detailed tutorial on installing and configuring MySql5.7 on Ubuntu 20.04

Table of contents 1. Ubuntu source change 2. Inst...

Detailed explanation of Vue life cycle functions

Table of contents Lifecycle Functions Common life...

Detailed explanation of CSS BEM writing standards

BEM is a component-based approach to web developm...

React passes parameters in several ways

Table of contents Passing parameters between pare...

Sample code for implementing menu permission control in Vue

When people are working on a backend management s...

Practical notes on installing Jenkins with docker-compose

Create a Directory cd /usr/local/docker/ mkdir je...

Linux kernel device driver Linux kernel basic notes summary

1. Linux kernel driver module mechanism Static lo...

Tutorial on using iostat command in Linux

Preface It is said that if the people doing opera...

Top 10 Js Image Processing Libraries

Table of contents introduce 1. Pica 2. Lena.js 3....

Explanation of the usage scenarios of sql and various nosql databases

SQL is the main trunk. Why do I understand it thi...