Ways to clear disk space on CentOS 6 or CentOS 7

Below is a quick command to clear disk space on CentOS 6 or CentOS 7 server.

First, you need to install the yum-utils package:

yum -y install yum-utils

1. Trim log files

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

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

2. Clean up YUM cache

Cleaning the yum cache is simple:

yum clean all

Please note that the above command will not delete all the files related to it that yum has installed.

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

rm -rf /var/cache/yum

In addition, when you accidentally yum pass a normal user (forgot sudo), yum will create a user cache. So we also delete it:

rm -rf /var/tmp/yum-*

3. Delete orphan package

Check the existing orphan package

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

Confirm to delete orphaned packages

Now, if you are satisfied with the advice given by the previous command, run:

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

4. Delete WordPress download cached by WP CLI

Every time you set up a new WordPress website, 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. Remove old kernel

Before deleting the old kernel, you may want to reboot first to boot from the latest kernel.

Because you can't remove the old kernel of the current boot system?

The following command will only keep the 2 latest kernels:

package-cleanup --oldkernels --count=2

Please note that for some VPS providers (such as Linode), the server uses the kernel built by the provider by default instead of the kernel of the server itself. Therefore, it does not make sense to keep more than one old kernel on the system. and so:

package-cleanup --oldkernels --count=1

6. Delete Composer cache

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

7. Delete core dump

If you have some serious PHP faults that cause it to segfault and core dumps are enabled, then it is very likely-you have many such faults.
They are not needed after you finish debugging the problem. and so:

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

8. Delete error_log file (cPanel)

If you use the disgusting cPanel, you will definitely have error_log spreading dozens of files in your web directory. If you can install Citrus Stack, that's much better. The temporary solution is to delete all 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 whole content of this article, I hope it will be helpful to everyone's study.

Recommended Posts

Ways to clear disk space on CentOS 6 or CentOS 7
How to increase swap space on CentOS 8
5 simple ways to free up space on Ubuntu
Configure swap space on CentOS7
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
How to install Memcached on CentOS 8
Install MATE or XFCE on CentOS 7
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
How to Update to gcc4.9.x on Centos7
How to install TeamViewer on CentOS 8
How to install Perl 5 on CentOS
How to install Git on CentOS 8
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Jenkins on CentOS 8
How to install Java on CentOS 8
How to install Go on CentOS 8
How to install GCC on CentOS 8
How to install Yarn on CentOS 8
How to install Nginx on CentOS 8
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
How to install Vagrant on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8
How to install Python on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
How to install htop on CentOS 8
How to install TeamViewer on CentOS 8
How to add swap on CentOS 7
How to install MariaDB on CentOS 8
How to install MongoDB on CentOS 7
How to install Odoo 13 on CentOS 8
How to install Apache on CentOS 8
How to disable SELinux on CentOS 8
How to install OpenCV on CentOS 8
How to install PHP on CentOS 8
How to install MongoDB on CentOS 8
How to add swap space on Ubuntu 20.04
How to install Apache Maven on CentOS 8
How to install Apache Kafka on CentOS 7
[Graphic] How to install tomcat on centos
R&D: How To Install Python 3 on CentOS 7
Explain Centos7 Expansion Disk Space (LVM Management)
How to install GCC compiler on CentOS 7
How to modify the hostname on CentOS 8
Three ways to install JDK under CentOS
How to install offline JDK1.8 on centos7.0
How to install Visual Studio Code on CentOS 8
How to install and use Docker on CentOS 7
How to install RPM packages on CentOS Linux