Home  >  Article  >  Operation and Maintenance  >  How to clear disk space on CentOS6 or CentOS7

How to clear disk space on CentOS6 or CentOS7

藏色散人
藏色散人Original
2021-06-27 17:19:213622browse

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 /varAll 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

The above is the detailed content of How to clear disk space on CentOS6 or CentOS7. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn