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