Debian/Ubuntu clear hard drive space

Debian/Ubuntu clean up hard disk space_debian clean up disk space_weixin_43606319's blog-CSDN blog

1. Delete remaining configuration files

Usually Debian /Ubuntu can use two commands to delete software packages

 
 
  1. sudo apt-get remove <package-name>

  2. sudo apt-get purge <package-name>

remove will delete the package but keep the configuration files. Purge will delete both software packages and configuration files.

Find out which packages on your system have left residual configuration files

dpkg --list | grep "^rc"

rc means that the package has been removed ( Remove ), but the configuration file ( Config -file) is still there. Now extract the names of these packages

dpkg --list | grep "^rc" | cut -d " " -f 3

Remove these packages

dpkg --list | grep "^rc" | cut -d " " -f 3 | xargs sudo dpkg --purge

If you just want to delete the configuration file of a certain package, you can use the following command

sudo dpkg --purge <package-name>

2. Delete useless deb software installation packages

Usually after we use the sudo apt-get install command to install the software package, the deb installation package downloaded by apt-get will remain on the system. So if you often install software, these deb installation packages will take up a lot of space. These installation packages are in the /var/cache/apt/archives directory. After the software installation is completed, these deb installation packages are of no use. For servers with limited hard disk capacity, the apt-get clean command can free up a lot of space. You can enter the following command to view the total size of the deb installation package in the /var/chace/apt/archives directory

du -sh /var/cache/apt/archives

 To delete these deb packages, just run the following two commands.

 
 
  1. sudo apt-get clean

  2. sudo apt-get autoclean

 3. Delete orphan packages

Sometimes, when you use apt-get to install a software package, other dependencies will be automatically installed. When you delete this package, these dependencies are no longer useful. These useless dependent packages are called orphan packages and can be deleted using the following command

sudo apt-get autoremove

However, apt-get autoremove will only delete the dependency packages automatically installed by apt-get, but the dependency packages you installed manually will not be deleted. In this case, we can use deborphan to completely delete them.

sudo apt-get install deborphan

 List orphan packages

deborphan

 delete them

deborphan | xargs sudo apt-get purge -y

4. Remove outdated packages

The so-called obsolete software package means that no software source in the /etc/apt/sources.list source file provides a deb installation package for this software. In other words, this software package cannot be found in the software source and is not supported. This may be due to the following reasons:

  • The upstream developers do not maintain the software, and there is no one to take over the development of the software. So the Debian/Ubuntu software package maintainers decided to delete this software from the software source.
  • The software became an orphan and had very few users. So it disappeared from the software source.
  • The software got a new name, and the maintainers gave it a new name and kept the old packages.

Because these outdated software will not have security updates and may cause trouble during the software upgrade process, we need to delete them. First find out which packages are outdated

sudo aptitude search ?obsolete

my output

i linux-image-3.2.0-29-generic - Linux kernel image for version 3.2.0 on 64

delete it

sudo apt-get purge linux-image-3.2.0-29-generic

You can also use the following command to clear all outdated software packages at once

sudo  aptitude purge ~o

However, it should be noted that although some software packages cannot be found in the software source, they are not outdated software packages. For example, you download and install ubuntu-tweak. Ubuntu-tweak requires you to download the deb installation package from the official website, but no software source is provided. Using the above command will also delete such software packages. So I recommend using apt-get purge and select the software packages you need to delete.

5. Clean up log files

The log files will become larger and larger. We can use the ncdu tool to view large log files.

 
 
  1. sudo apt-get install ncdu

  2. sudo ncdu /var/log

As can be seen from the picture above, shadowsocks.log occupies 24.5MiB of hard disk space. We can use the following command to clear the contents of this log file.

sudo dd if=/dev/null of=/var/log/shadowsocks.log

6. baobab hard disk space usage analysis tool

baobab is a graphical interface tool that can help us find which directory or file takes up a lot of space in the system. Run the following command in the terminal

baobab

As you can see from the picture above, the email in thunerbird is 14.3GB in size! There are also chromuim browser, Spotify music player , Google Chrome , and thumbnails. These caches also take up a lot of space.

In fact, we can also use the ncdu tool mentioned above to view large-capacity directories and files. For example, view /home/<username>/

sudo ncdu /home/<username>

However, when using ncdu, you need to enter a command every time you view a directory. It is recommended to use ncdu on the server and the graphical baobab tool on the desktop version.

7. Delete bulk software packages

First install debian-goodies

sudo apt-get install debian-goodies

Then enter the following command

dpigs -H

my output

 
 
  1. 441.0M texlive-latex-extra-doc

  2. 230.1M valgrind-dbg

  3. 200.6M chromium-browser

  4. 171.4M google-chrome-stable

  5. 153.4M linux-image-extra-3.19.0-39-generic

  6. 153.4M linux-image-extra-3.19.0-37-generic

  7. 151.5M maltego

  8. 144.8M wine1.7-amd64

  9. 140.6M metasploit-framework

  10. 137.4M wine1.7-i386

Next you can delete the packages you don't use. The above command will only display the first 10 results by default. You can specify the number of results, such as 20

dpigs -H --lines=20

8. Use ubuntu-tweak to clean up

Go to the ubuntu-tweak official website to download the deb installation package, and then enter the following command to install.

 
 
  1. sudo apt-get install gdebi

  2. sudo gdebi ubuntu-tweak*.deb

After opening ubuntu tweak, select the Janitor tab. Here you can clean application cache, thumbnail cache, apt cache, old kernels, unused package configuration files, and orphan packages.

 

Guess you like

Origin blog.csdn.net/sinat_30603081/article/details/132223968