How to clear disk space on CentOS6 or CentOS7

藏色散人
Release: 2021-06-27 17:19:37
Original
3607 people have browsed it

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
Copy after login

1. Trim the log file

find /var -name "*.log" \( \( -size +50M -mtime +7 \) -o -mtime +30 \) -exec truncate {} --size 0 \;
Copy after login

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 \;
Copy after login

2 .Clean YUM cache

Cleaning yum cache is simple:

yum clean all
Copy after login

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
Copy after login

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-*
Copy after login

3. Delete Orphan Packages

Check existing orphan packages

package-cleanup --quiet --leaves --exclude-bin
Copy after login

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
Copy after login

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/*
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template