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-utils
# curl -Ls http://bit.ly/clean-centos-disk-space | sudo bash
# find /var -name "*.log" \( \( -size +50M -mtime +7 \) -o -mtime +30 \) -exec truncate {} --size 0 \;
# yum clean all
# rm -rf /var/tmp/yum-*
# package-cleanup --quiet --leaves | xargs yum remove -y
# rm -rf /root/.wp-cli/cache/*
# rm -rf /home/*/.wp-cli/cache/*
# (( $(rpm -E %{rhel}) >= 8 )) && dnf remove $(dnf repoquery --installonly --latest-limit=-2 -q)
# (( $(rpm -E %{rhel}) <= 7 )) && package-cleanup --oldkernels --count=2
# rm -rf /root/.composer/cache
# rm -rf /home/*/.composer/cache
# find -regex ".*/core\.[0-9]+$" -delete
error_log
files (CPanel):# find /home/*/public_html/ -name error_log -delete
# rm -rf /root/.npm /home/*/.npm /root/.node-gyp /home/*/.node-gyp /tmp/npm-*
# rm -rf /var/cache/mock/* /var/lib/mock/*
# rm -rf /home/*/.cache/*/* /root/.cache/*/*
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!