In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the garbage cleaning methods in Linux system". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what garbage cleaning methods are there in the Linux system?"
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:
The code is as follows:
Uname-r
You should see an output like this:
The code is as follows:
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:
The code is as follows:
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:
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 10 KB
Total/best extents 128413/128382
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.
General ways to clean up the disk
1. Scan important file systems regularly, compare them, and analyze which files are read and written frequently
The code is as follows:
# IS-IR/home >; files.txt
# diff filesold.txt files.txt
By analyzing the growth of the predicted space, we can also consider compressing the files that read and write infrequently to reduce the space occupied.
two。 View the inodes consumption of the spatial file system
The code is as follows:
# df-i/home
If there is still a large number of inpde available, it means that large files take up space, otherwise thieves may take up a large number of small files.
3. Find out the directory that takes up more space.
View the space occupied by / home
The code is as follows:
# du-hs/home
View / home occupies more than 1000m space
The code is as follows:
# du/awk'$1 >; 2000'
4. Find out the files that take up more space.
The code is as follows:
# find/home-size + 2000K
5. Find files that have been recently modified or created
First TOUCH a file of the time you want is 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. Connect the partition
In a partition with space, make a connection to the partition that has no space.
The code is as follows:
# in-s/home/use/home
7. Find a process that consumes a lot of space
According to different applications, find out the corresponding process and analyze the reasons.
8. Check and repair the file system
The code is as follows:
# fsck-y/home
9. Restart the machine
With the above ten tips, you should be able to solve most of the problems, but the key is to plan the partition during installation. In addition, it is found that the disk is rough, can not be urgent, operate carefully, carefully analyze the reasons, and then deal with it carefully. Need to note that the above ten moves do not need to be carried out sequentially, some may seal the throat in one move, and some may need to use several moves at the same time, delete operations must be careful. If it doesn't work, we can only take "hard" measures such as adding the hard drive and reinstalling the system.
You can also:
The code is as follows:
Cd/
Du-h--max-depth=q/grep M/sort-n
Find the largest directory and enter it
Run again
The code is as follows:
Du-h-max-depth=1/grep M / sort-n
Find out the documents to see if they are useful.
Delete it if it's useless.
It is hoped that the above cleaning method steps can bring a certain release of disk space to the users operating the linux system.
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:
The code is as follows:
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:
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 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 in mind that 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.
At this point, I believe you have a deeper understanding of "what garbage cleaning methods are available in the Linux system". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.