Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to keep the Linux system clean and tidy

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you how to make the Linux system clean and tidy, the content is very detailed, interested friends can refer to, hope to be helpful to you.

One of the biggest advantages of Linux is that it is still stable after using it for some time. The biggest challenge for Linux is to install it and find and configure the software you need to get the job done. 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 and stays on the hard drive while it is running. As we all know, as this kind of data accumulates over time, Windows will naturally slow down, and Windows users will either install software to clean up all this junk data, or reinstall the system regularly to make people feel refreshed. In fact, there is an entire industry dedicated to selling "cleanup tools" for Windows. Some of these software are actually "sheep's clothing" malware, but many of them are quite useful. The key, of course, is to figure out which is the really good tool.

If you use Linux, you may be glad you don't have to deal with this kind of annoyance, but don't be happy too soon. Although Linux is not as dirty as Windows, it does benefit somewhat from occasional cleanup work. Linux also generates data during operation, such as logs, cached data, and temporary files. These additional data usually do not affect the performance of the system. The main reason for wanting to clean up this data is to recover the hard disk space occupied. If you are running solid state drives (SSD), this may be something you care about, because the capacity of solid state drives is often not as large as the traditional hard drives we are used to, so we have to keep a close eye on the space consumed until the price of high-capacity solid state drives comes down a little bit. Here are a few key points that can be taken to clean up the Linux system.

Clear the old kernel

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

Each Linux distribution handles kernel management differently. Some have excellent GUI tools that let you choose which kernel to run, such as OpenSUSE, Linux Mint, and Manjaro. Other distributions rarely or never update the kernel, leaving the task of manual update entirely to the user. The kernel is very important, and having an updated kernel is one of the main means to ensure that your system is secure and away from viruses and hackers. I'll focus on Ubuntu here, but encourage you to take a closer look at the kernel and see how the distribution you use handles kernel updates.

Ubuntu updates the kernel along with everything else on the system, leaving the old kernel behind. Kernel updates 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 leaves the old kernel there completely; after a while, you end up with a lot of old kernels installed on your system. The kernel and related files take up a lot of space, up to hundreds of MB. Therefore, cleaning up the old kernel can free up a lot of space.

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

Uname-r

You should see an output like this:

3.16.0-38-generic

This is the version number of the currently running kernel and we need to write it down because we want to make sure that nothing is done with the kernel or any files that come with it.

Now that we know what version to run, we can next open the manager to see if any old kernels are taking up space. To find the kernel, type "linux-image" into the search box and sort the list by 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 list of files installed with it. You don't have to clean them up one by one, highlight the main kernel image package and mark it to clear completely from the right-click menu to allow the system to clear all files associated with it. Be sure to check the version number repeatedly to make sure that the current version is not cleared. If you sort the list by installed packages, the latest running kernel should appear at the top of the list. You can now mark all the old kernels, but you need to look for another package before you click the "apply" button.

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

Use BleachBit

There are some really good Linux programs that automatically check the system and clear extra files. One of the programs I always use is BleachBit. It has a long history and is available on almost every Linux distribution. I haven't encountered any problems with using it to clean up any abnormal files on the system. BleachBit is lightweight, but it provides some fairly powerful features. We will only cover the very basic features here, but it will take some time to gain an in-depth understanding of its skills, and you will find some advanced features useful.

Once you have installed BleachBit, you will see two entries corresponding to it in the dashboard or application menu. One allows you to run it as root, and the other to run it as yourself. Running as you will erase files related to your account, while running as root will erase data such as cache packages and system logs. BleachBit also allows you to clear the cached content of Web browsers, email clients, and plug-ins that may be installed on the 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 okay, but if you use someone else's account to run it, it may make users unhappy. I have found that leaving other settings unchanged, simply emptying the cache in Web browsers can reclaim a lot of space.

Running BleachBit as root allows you to use the APT cleanup command to empty cache packages and updates on your system. You can use the clean, auto clean and auto remove commands in the terminal, but it's all done for you here. Speaking of terminals, BleachBit can also be used here. You can execute the "bleachbit" command, and it will run at the default value that you configure with GUI. This is good, because it means that you can make a Bash script that automatically cleans up the system.

Defragment the hard disk

It has been said many times: one of the advantages of running Linux is that it is never necessary to defragment the hard drive. In fact, this is not entirely the case. Most ordinary users never need to worry about file defragmentation because defragmentation is not so serious as to affect the performance of rotating hard drives. The ext4 file system is very good at storing files in a way that is not defragmented. Unlike the NTFS file system used on Windows, ext4 spreads data across the hard drive, grouping similar files into one category, leaving a lot of room for file growth without defragmentation. This means that as long as you have a lot of free space on your hard drive, you may not need to defragment at all. My system has been running for two or three years, and after checking the hard drive, I found that the defragmentation score is "0", which indicates that defragmentation is not needed at all.

That being the case, why should I bother to tell you to defragment? In some cases, you may need to consider defragmentation, for example, if your hard drive starts to fill up. Any ext4 rotating hard drive that takes up more than 80% of the space tends to start defragmenting files because the system divides the files, making it harder to ensure that more space is added. Another situation that causes file defragmentation is if you have a large number of very large documents. If users deal with a lot of video production, large databases or virtual machines, they end up with a lot of very large files. After a period of time, the fragmentation of these files will become so serious that running defragmentation will significantly improve the performance of the hard drive.

Open the terminal and execute this command to see if your system needs to be defragmented:

Sudo e4defrag /-c

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

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

The main parameter we focus on is the defragmentation score. It's 0 here, so we don't have to worry about hard disk defragmentation. If your home folder is not in its own partition, you really should change / to / home and check the defragmentation status there. If you want to run the defragmenter, just execute the command without the-c argument:

Sudo e4defrag /

It then checks the file system and defragments the files that need to be defragmented. In this process, a large number of output results will be scrolled. 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 shut down the system when you're done. To do this, you can execute commands like this:

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

What I usually do now is to run the defragmentation tool after installing the new system and reversing all the files. After that, I occasionally check the status, and I find that the defragmentation score has been basically kept at 0 since then.

It's worth mentioning that you don't have to defragment the solid state drive at all. In fact, executing the above command on a solid-state drive usually pops up a message that this operation is not allowed. Those who only use solid state drives can skip this section at all.

One last word: after defragmenting the hard drive in Linux, don't expect a big improvement in performance, because even if there are some fragmented files on the hard drive, ext4 is actually good at running fast. * * remember: * * ext4 was designed with a high input / output file server in mind, which is very efficient. Even if you have to deal with laptops or desktops, it will not be "out of breath".

Don't pursue cleanliness too much!

Some computer users are making sure that the system is clean and running at maximum performance. * * keep one thing in mind: * * many Linux systems have been running for many years without taking the above measures at all. Linux doesn't slow down like Windows or Mac at all, even after a long time of use. The main reason you want to empty files is to reclaim hard disk space or to control the size of full system backups. If you like to try different distributions all the time as much as everyone else, you probably don't need to do any of the above at all, just because you're reinstalling frequently. However, it is always good to know that there are such tools.

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

On how to make the Linux system clean and tidy to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report