How to make your Linux system clean and tidy

Source: Internet
Author: User
Tags tidy linux mint

How to make your Linux system clean and tidy

One of the biggest advantages of Linux is that it remains stable after a period of time. The biggest challenge for Linux is to install it and find and configure the software you need to complete your work. Once you have completed this 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 large amount of extra data during running and remains on the hard disk. As we all know, after a period of time, as such data continues to accumulate, the running speed of Windows will naturally slow down. At this time, Windows users will either install software to clear all the junk data, or reinstall the system on a regular basis, so that the startup speed is refreshing. In fact, there is a whole industry dedicated to selling "Cleaning tools" for Windows ". Some of these software are actually malicious software in sheepskin, but many of them are quite useful. Of course, the key is to find out which is a really good tool.

If you use Linux, you may be glad that you don't have to deal with such troubles, but don't be too happy. Although Linux is not as dirty as Windows, it does benefit from occasional cleanup. Linux also generates data during running, including logs, cached data, and temporary files. This extra data usually does not affect the system performance. The main reason for clearing the data is to reclaim the occupied hard disk space. If you are running solid state disks (SSDs), this may be something you care about, because the capacity of Solid State disks is often inferior to the traditional hard disks we are used, therefore, we need to pay close attention to the occupied space until the price of a large-capacity SSD is lowered. The following describes the main points that can be taken to clean up the Linux system.

 

Clear old Kernel

Warning! Be extremely careful when clearing anything related to the Linux kernel! Clearing the wrong software package is likely to paralyze your computer or completely become junk! We warned you!

Each Linux release has different kernel management methods. Some excellent GUI tools allow you to choose the kernel to run, such as OpenSUSE, Linux Mint, and Manjaro. In other releases, the manual update task is handed over to users because the kernel is rarely or never updated. The kernel is very important. An updated kernel is one of the main means to ensure system security and stay away from viruses and hackers. I will introduce Ubuntu here, but I encourage you to study the kernel in depth to understand how the release you are using handles Kernel updates.

Ubuntu updates the kernel together with everything else on the system and leaves the old kernel. Kernel updates occasionally cause problems, so it is best to keep the old kernel. In this case, you can recover to the old kernel. The problem is that Ubuntu completely keeps the old kernel there. After a while, you finally installed a lot of old kernels on your system. The kernel and Related Files occupy a large amount of space, up to several hundred MB. Therefore, clearing the old kernel can free up a lot of space.

The best tool for managing the kernel in Ubuntu is the newly established Package Manager (Synaptic Package Manager ). If it has not been installed on your system, install it now. Before you open the manager, open the terminal and run the following command:

  1. uname -r 

You should see the output result similar to this:

  1. 3.16.0-38-generic 

This is the version number of the currently running kernel. You need to write it down, because we want to ensure that no operation is performed on this kernel or any files that are included with it.

As we know what version to run, we can open the manager to see if there is any space occupied by the old kernel. To find the kernel, enter "linux-image" in the search box and sort the list by installed version. To this end, you can click the title of the software package list. Even if you have installed only one version of the kernel, you will see a lot of files installed with it. You do not need to clear them one by one, highlight the main kernel image package, and mark it as completely cleared from the right-click menu, this allows the system to clear all related files. Check the version number repeatedly to ensure that the current version is not cleared. If you sort the list by installed software packages, the latest running kernel will appear at the top of the list. Now you can mark all the old kernels, but you still need to find another software package before clicking the "application" button.

Clear the search box and search for "linux-headers ". If they have been installed, you should obtain a list of all installed Linux title files related to the kernel installed on the system. The version number is associated with the kernel, so make sure that you have not cleared the title file of the current version. In fact, the title file is not necessary for daily operations on the computer, but it is good to have a title file if you want to compile a program or driver from the source code. They do not occupy much space, so I always leave the title file of the running kernel on the system.

 

Use BleachBit

Some really good Linux programs can automatically check the system and clear additional files. A program I always use is BleachBit. Its history is not short. Almost every Linux release has it. I used it to clear any abnormal files on the system and haven't encountered any problems. BleachBit is lightweight, but it provides some powerful features. We will only introduce basic functions here, but it takes some time to gain an in-depth understanding of its skills. You will find some advanced functions very useful.

Once BleachBit is installed, two corresponding entries are displayed in the dashboard or application menu. One allows you to run it as the root user, and the other allows you to run it as yourself. Use your own shipping line to clear files related to your account, and use the root user to clear data such as cached software packages and system logs. BleachBit also allows you to clear the cache content of Web browsers, email client programs, and plug-ins that may be installed on the system. Be careful when selecting here, because it will clear 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 users unhappy. I found that, keeping other settings unchanged, simply clearing the cache in the Web browser can reclaim a large amount of space.

Run BleachBit as the root user so that you can use the APT cleanup command to clear the cache packages and updates on your system. You can use the clean, auto clean, and auto remove commands on the terminal, but they are all done here. When it comes to terminals, BleachBit can also be used here. You can execute the "bleachbit" command to run it based on the preset values configured in the GUI. This is good because it means you can create a Bash script to automatically clean up the system.

 

Fragment of Hard Disks

It has been said many times: One of the advantages of running Linux is that there is no need to fragment hard disks. Not exactly. Most common users never have to worry about file fragmentation, because fragmentation does not seriously affect the performance of the rotating hard disk. The ext4 file system is very good at storing files in a way that does not fragment. Unlike the NTFS file system used on Windows, ext4 distributes data across the hard disk and classifies similar files as one type so that there is no need to fragment, which leaves a lot of space for file growth. This means that as long as you have a large amount of idle space on the hard disk, you may not need to fragment. My system has been running for two or three years. After checking the hard disk, I found that the fragment score is "0", which indicates that no fragment is required.

In this case, why bother telling you how to organize the fragments? In some cases, you may need to consider fragment, for example, if your hard disk begins to fill up. Any ext4 hard drive that occupies more than 80% of the space will often start to fragment the file, because the system splits the file separately to ensure that the increase in space will start to become more difficult. Another scenario that causes file fragmentation is if you have a large number of very large files. If a user processes a large number of videos to make and process large databases or virtual machines, the user will eventually face a large number of very large files. After a while, the fragmentation of these files will become very serious, and running fragment will significantly improve the hard disk performance.

Open the terminal and execute this command to see if your system requires fragmentation:

  1. sudo e4defrag / -c 

Enter the password and the program will quickly analyze your file system. If you have many files, this process may take one minute, so be patient. You should see the output result similar to this:

  1. now/best size/ext 
  2. 1. /var/log/syslog 3/1 4 KB 
  3. 2. /var/log/samba/log.nmbd 2/1 4 KB 
  4. 3. /var/log/boot.log 2/1 4 KB 
  5. 4. /var/log/auth.log 3/1 5 KB 
  6. 5. /var/log/ConsoleKit/history 3/1 10 KB 
  7.  
  8. Total/best extents 128413/128382 
  9. Average size per extent 41 KB 
  10. Fragmentation score 0 
  11. [0-30 no problem: 31-55 a little bit fragmented: 56- needs defrag] 
  12. This directory (/) does not need defragmentation. 
  13. Done. 

The main parameter we focus on is the fragment score. It is 0 here, so we don't have to worry about hard disk fragmentation. If your main folder is not in its own partition, you should replace/with/home and check the fragment status. If you want to run the defragmentation program, you only need to execute the command without the-c parameter:

  1. sudo e4defrag / 

Then, it checks the file system and fragment the files to be fragment. In this process, a large number of output results are displayed in scrolling mode. If you have a lot of files on your system, this is a long process, so you can let the fragment program start to run before going to bed at night, and then shut down the system. Therefore, you can execute a command like this:

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

What I usually do today is to run the fragment tool after installing the new system and dumping all the files. After that, I will check the status occasionally. I found that the fragment score remained basically at 0.

It is worth mentioning that you do not have to fragment the SSD. In fact, executing the above command on a solid state disk usually prompts a message indicating that this operation is not allowed. Those who only use SSD do not need to read this section.

Finally, do not expect a significant improvement in performance after the hard disk fragment in Linux, because ext4 is actually good at fast running even if there are some fragment files on the hard disk. Remember: ext4 was designed to take into account the high input/output file server, which is very efficient. Even if you want to process a laptop or desktop, it will not be panting ".

 

Don't overdo clean!

Some computer users make sure that the system is clean and running at the highest performance. Keep in mind that many Linux systems have been running for many years without taking the above measures. Linux does not slow down like Windows or Mac, even after a long period of use. The main reason you want to clear the file is to reclaim the hard disk space or control the size of the full system backup. If you like to try different releases all the time, you probably don't need to take any of the above measures at last, because you are frequently reinstalling them. However, it is always good to know such tools.

This article permanently updates the link address:

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.