Here are the quick commands 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 the log file
find /var -name "*.log" \( \( -size +50M -mtime +7 \) -o -mtime +30 \) -exec truncate {} --size 0 \;
This will truncate the *.log
volume /var
All files older than 7 days and larger than 50M or older than 30 days.
There are also some files with the extension *.log.gz
, or *.journal
, you can refer to this method:
find /var/log -regex '.*\.log\|.*\.journal\|.*\.gz' \( \( -size +5M -mtime +7 \) -o -mtime +30 \) -exec truncate {} --size 0 \;
2 .Clean YUM cache
Cleaning yum cache is simple:
yum clean all
Please note that the above command will not delete all files related to yum that has been installed.
You may want to free up the space occupied by orphaned data in a disabled or deleted repository:
rm -rf /var/cache/yum
Additionally, when you accidentally yum
via a normal user (forgot sudo), yum will create user cache. So we delete it too:
rm -rf /var/tmp/yum-*
3. Delete Orphan Packages
Check existing orphan packages
package-cleanup --quiet --leaves --exclude-bin
Confirm to delete orphan packages
Now, if yes to the previous Once you are satisfied with the suggestions given by the command, run:
package-cleanup --quiet --leaves --exclude-bin | xargs yum remove -y
4. Delete WP CLI cached WordPress downloads
The WP CLI saves WordPress archives every time you set up a new WordPress site. 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 deleting the old kernel, you may want to reboot first so that you can boot from the latest kernel.
Because you cannot remove the old kernel that is currently booting the system