Summary of garbage cleaning methods for Linux systems

Source: Internet
Author: User
Tags file system touch linux mint

One of the biggest advantages of Linux is that it's still stable after a while. The biggest challenge for Linux is to install it and find and configure the software you need to complete your work. Once you have finished the task, it will almost run smoothly. As for system maintenance, there is not much to worry about. On the other hand, Windows is what I call a "dirty" system because it generates a lot of extra data during the run and stays on the hard drive. As we all know, after a period of time, as this type of data accumulates, windows will naturally slow down, when Windows users either install software to clean up all of the junk data, or reload the system periodically to make it feel like a fresh start. In fact, there is an entire industry dedicated to selling Windows-oriented "cleanup tools." Some of these software are actually "sheepskin" malware, but many are quite useful. The key, of course, is figuring out which is the really good tool.

If you use Linux, you may be glad you don't have to deal with this sort of thing, but don't get too excited. Although Linux is not as dirty as windows, it does benefit from occasional cleanup efforts. Linux also generates data during the run, with logs, cached data, and temporary files. These additional data usually do not affect the performance of the system. The main reason you want to clean up this data is to reclaim the hard disk space that is occupied. If you're running a solid-state drive (SSD), that's probably what you care about, because SSD is often less than the traditional hard drive we used to use, so we need to keep a close eye on space until the price of a large, solid-state drive drops. Here are some of the key points you can take to clean up your Linux system.

Clear Old kernel

Warning! Be extremely careful when removing anything related to the Linux kernel! Cleaning up the wrong package is likely to cause your computer to become paralyzed or completely rubbish! We warned you!

Each Linux distribution handles kernel management in a different way. Some have excellent GUI tools that allow you to choose which kernel to run, such as openSUSE, Linux Mint, and Manjaro. Other distributions have little or no updates to the kernel, and the task of manually updating is completely given to the user. The kernel is very important, and having an updated kernel is one of the main ways you make sure your system is secure, away from viruses and hackers. I'll focus on Ubuntu here, but encourage you to delve into the kernel and see how the distribution you use handles kernel updates.

Ubuntu updates the kernel along with everything else on the system and leaves the old kernel behind. Kernel updates can occasionally cause problems, so it's best to keep the old kernel. That way, if necessary, you can revert to the old kernel. The problem is that Ubuntu left the old kernel there completely, and after a while, a whole bunch of old kernels were installed on your system. The kernel and related files occupy a lot of space, up to hundreds of MB. Thus, clearing the old kernel frees up a lot of space.

The best tool for managing the kernel under Ubuntu is the newly-established Package Manager (Synaptic Package manager). If it's not installed on your system, install it now. Before you open the manager, open the terminal and execute the command:

The code is as follows:

Uname-r

You should see output similar to this:

The code is as follows:

3.16.0-38-generic

This is the version number of the kernel that is currently running and needs to be written down because we want to make sure that there is no action on the kernel or any files accompanying it.

Since we know what version to run, we can then open the manager to see if any of the old cores are taking up space. To find the kernel, simply type "linux-image" into the search box and sort the list by the installed version. To do this, you can click on the title of the package list. Even if you install only one version of the kernel, you will see a large stack of files that are installed with it. You don't have to clean them up one after the other, highlight the main kernel image package and mark it as completely erased from the right-click menu to let the system clear all the files associated with it. Be sure to double-check the version number to ensure that the current version is not cleared. If you sort the list by an installed package, the latest running kernel should appear on the top of the list. You can now mark all the old kernels, but before you click the "Apply" button, you'll need to look for another package.

Empty the search bar and search for "Linux-headers" now. If they are installed, you should get a list of all the installed Linux banner files that are relevant to the kernel installed on the system. The version number accompanies the kernel, so make sure you don't erase the current version of the header file. In fact, header files are not necessary for the day-to-day operation of a computer, but if you want to compile a program or driver from a source code, a header file is good. They don't take up too much space, so I always leave the title file of the running kernel on the system.

Using Bleachbit

There are some really good Linux programs that can automatically check the system and clear extra files. One of the programs I always use is bleachbit. It's not a short history, it's on almost every Linux distribution. I have not encountered any problems with it to clear any exception files on the system. Bleachbit is lightweight, but offers some pretty powerful features. We only introduce very basic functions here, but it takes a while to get a thorough understanding of its capabilities, and you will find some advanced features useful.

Once you have installed the Bleachbit, you will see two entries in the dashboard or application menu that correspond to it. One allows you to run it as a root user, and another to run it yourself. Running on your own will erase the files associated with your account, and running with the root will clear data such as cache packages and system logs. Bleachbit also allows you to empty cached content for Web browsers, e-mail clients, and plug-ins that may be installed on your system. Be careful when choosing here, as it will erase all your saved passwords and settings; If you want to clear everything, it may be nothing, but if you use someone else's account to run it, it may make the user unhappy. I found that by keeping the other settings unchanged, just emptying the cache in the Web browser would reclaim a lot of space.

Running Bleachbit with the root user allows you to use the APT cleanup command to empty the cache packages and updates on your system. You can use clean, auto clean and Auto remove commands in the terminal, but it's all done for you here. When it comes to terminals, bleachbit can also be used here. You can execute the "bleachbit" command, and it will run with the preset values you configured with the GUI. This is good because it means you can make a bash script that automatically cleans the system.

Defragment a hard disk

I've said this many times: one of the advantages of running Linux is that you never need to defragment your hard disk. In fact, it is not entirely so. Most ordinary users never have to worry about file defragmentation, because fragmentation does not seriously affect the performance of a spinning hard disk. The Ext4 file system is very good at storing files in a way that does not defragment them. Unlike the NTFS file system, which is used on Windows, ext4 the data across the hard disk, putting similar files in a category so that there is a lot of room for the growth of the file without defragmenting it. This means that if you have a large amount of unused space on your hard disk, you may not need to defragment it at all. My system has been running for two or three years, and after checking the hard drive, I found that the defragmentation score was "0", which means there's no need for defragmentation at all.

So why do I bother to tell you to defragment it? In some cases, you may want to consider defragmentation, such as if your hard drive starts to fill up. Any EXT4 rotating hard disk that has occupied more than 80% space often starts defragmenting the file, because the system separates the files to make sure that the increase in space starts to become more difficult. Another scenario that causes file defragmentation is if you have a large number of very big files. If users process large amounts of video production, process large databases or virtual machines, they will end up with a huge stack of files. After a while, the fragmentation of these files becomes very serious, and running defragmentation can significantly improve the performance of your hard disk.

Open the terminal, execute this command, and see if your system needs to defragment:

The code is as follows:

sudo e4defrag/C

Enter your password and the program will quickly analyze your file system. If you have a lot of files, this process may take 1 minutes, so be patient. You should see output similar to this:

The code is as follows:

Now/best Size/ext

1./var/log/syslog 3/1 4 KB

2./VAR/LOG/SAMBA/LOG.NMBD 2/1 4 KB

3./var/log/boot.log 2/1 4 KB

4./var/log/auth.log 3/1 5 KB

5/var/log/consolekit/history 3/1 KB

Total/best extents 128413/128382

Average Size per extent MB

Fragmentation score 0

[0-30 no problem:31-55 a little bit fragmented:56-needs defrag]

This directory (/) does is not need defragmentation.

Done.

General how to clean up your disk

1. Regular scanning of important file systems, and comparison, analysis of those documents often read and write

The code is as follows:

#IS-ir/home>;files.txt

#diff Filesold.txt Files.txt

By analyzing the growth of the predicted space, you can also consider compressing the infrequently read and write files to reduce space usage.

2. View the inodes consumption of the space file system

The code is as follows:

#df-i/home

If there are a large number of inpde available, indicating that large files occupy space, no thief may be a large number of small files occupy space.

3. Find a large footprint directory

View space occupied by/home

The code is as follows:

#du-hs/home

View footprint over 1000m under/home

The code is as follows:

#du/awk ' $1>;2000 '

4. Find a document that occupies a larger space

The code is as follows:

#find/home-size +2000k

5. Find the most recently modified or created file

First touch a file with the time you want as follows

The code is as follows:

#TOUCH-T 08190800 Test

#find/home-newer Test-print

Delete Log

The code is as follows:

#rm-rf/var/log/*

6. Make connections to partitions

In a space partition, make a connection to an empty partition

The code is as follows:

#in-s/home/use/home

7. Find a process that consumes a lot of space

According to the different application, find the corresponding process, analyze the reason.

8. Check and Repair file system

The code is as follows:

#fsck-y/home

9. Reboot the Machine

With the above 10 strokes, you should be able to solve most of the problems, but the key is to plan the partition when installing. Also found that the disk is quite, not urgent, careful operation, serious analysis of the reasons, and then carefully deal with. Need to note that the above ten strokes do not need sequential execution, some may be a recruit seal throat, some may need to use several strokes, delete operation must be careful. If not, only to take the additional hard drive, reinstall the system and other "hard" way

It's OK:

The code is as follows:

cd/

Du-h--max-depth=q/grep M/sort-n

Find the largest directory and enter the directory

Run again

The code is as follows:

Du-h-max-depth=1/grep M/sort-n

Find out if it's a useful file after you look it up

Delete it if it doesn't work.

It is hoped that the above cleanup method steps will give the user who operates the Linux system a certain release of disk space.

The main parameter we are concerned with is the defragmentation score. It's 0 here, so we don't need to worry about defragmenting the hard disk. If your home folder is not in its own partition, then you really should change it to/home and check the defragmentation status there. If you want to run the defragmenter, just execute the command without the-C parameter:

The code is as follows:

sudo e4defrag/

It then checks the file system to defragment the files that need to be defragmented. In this process, there will be a large number of output results scrolling display. If you have a lot of files on your system, it's a long process, so you can get the defragmenter running before you go to bed at night, and then shut down the system. To do this, you can execute a command like this:

The code is as follows:

sudo e4defrag/&& sudo e4defrag/home && sudo shutdown-h now

What I usually do now is to run the defragmentation tool after I finish installing the new system and turn all the files upside down. After that, I would check the status occasionally, and I found that the defragmentation score was basically kept at 0 since then.

It is worth mentioning that you do not need to defragment the solid-state hard disk. In fact, executing the above command on a solid-state hard drive usually pops up a message indicating that the operation is not allowed. Those who use only solid-state drives are not allowed to look at this section at all.

Finally, after defragmenting your hard disk in Linux, don't expect a significant performance boost, because even though there are some fragmented files on your hard disk, Ext4 is really good at running fast. Remember: EXT4 was designed with high input/output file servers in mind, and it's very efficient. Even if you're working on a laptop or a desktop, it's not "panting".

Don't go overboard with the pursuit of cleanliness!

Some computer users are making sure that the system is clean and running at maximum performance. Keep in mind that many Linux systems have been running for years without taking the above steps. Linux does not slow down like windows or Macs at all, even after a long time of use. The main reason you want to empty the file is to recover the hard disk space or to control the size of the full system backup. If you like to keep experimenting with different distributions as much as anyone else, it is likely that you will end up not taking any of these measures because you are reloading frequently. However, it is always good to know that there are such tools.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.