If you've found this page, it's most likely because you're seeking for a solution to free up some disk space on a CentOS 6 or CentOS 7 or CentOS 8 system.
In this post, I'll try to highlight several simple ways that may be readily executed using the command-line / terminal to complete such tasks; each command has been tried on a CentOS 6 or CentOS 7 or CentOS 8 system, but the majority of them will also function on any other Linux environment.
The following are quick commands to clear disk space on CentOS 6 or CentOS 7 and CentOS 8 servers.
The first step before everything you need to run the below command:
# yum -y install yum-utilsAuto-cleaning your server by executing the below command:# curl -Ls http://bit.ly/clean-centos-disk-space | sudo bashDo you like to clear your server manually? So follow the below steps1. Trim log files:# find /var -name "*.log" \( \( -size +50M -mtime +7 \) -o -mtime +30 \) -exec truncate {} --size 0 \;2. Yum cache:# yum clean all# rm -rf /var/tmp/yum-*3. Orphan packages:# package-cleanup --quiet --leaves | xargs yum remove -y4. WP CLI caches:# rm -rf /root/.wp-cli/cache/* # rm -rf /home/*/.wp-cli/cache/*5. Old kernels:# (( $(rpm -E %{rhel}) >= 8 )) && dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q) # (( $(rpm -E %{rhel}) <= 7 )) && package-cleanup --oldkernels --count=26. Composer caches:# rm -rf /root/.composer/cache# rm -rf /home/*/.composer/cache7. Core dumps:# find -regex ".*/core\.[0-9]+$" -delete8. error_log files (CPanel):# find /home/*/public_html/ -name error_log -delete9. NodeJs caches:# rm -rf /root/.npm /home/*/.npm /root/.node-gyp /home/*/.node-gyp /tmp/npm-*10. Mock caches:# rm -rf /var/cache/mock/* /var/lib/mock/*11. Generic program caches:# rm -rf /home/*/.cache/*/* /root/.cache/*/*Conclusion
That's all there is to it: I genuinely hope that the scripts above will assist you in cleaning up your CentOS drive and freeing up some disk space. If you have any further general-purpose recommendations that may be utilized to complete such a work, please email us and we will gladly add them to this page!