How Linux uses the command line to clean up the disk to increase the space

  

Our disk space often takes a long time to become full, or only a small amount affects the speed of the system, so how do we solve this problem? Cleaning is a good way. Today, Xiaobian teaches you how to use the command line to clean up system garbage.

Solution:

1, is greater than 10M linux find the file

find -type f -size + 10000k

2,. Delete all empty directories

find /data -type d -empty -exec rm -rf {} \\;

3. How to delete empty files (files with size equal to 0) in batches under linux

find /data -type f -size 0c -exec rm -rf {} \\;

find /data -type f -size 0c| Xargs rm –f

4, delete the file five days ago

find /data -mtime +5 -type f -exec rm -rf {} \\;

5, delete the duplicate parts of the two files, print other

cat 1.txt 3.txt | Sort | Uniq

Installation: rpm -ivh gcc-c++-4.1.1-52.el5.x86_64.rpm

Delete: rpm -e gcc-c++-4.1.2-44.el5 - -nodeps

View the installation package: rpm -q gcc-c++

Add a method

1. Monitor important file systems regularly

The file system scans and compares the results of each scan to analyze which files are often read and written. Through analysis, we predict the growth of space. At the same time, we can consider compressing and storing large files that are not frequently read and written to reduce the space they occupy.

#ls -lR /home >files.txt

#diff filesold.txt files.txt

Compress the directory /home/odd that is not frequently read or written :

#tar cvf odd.bak /home/odd

#compress odd.bak

2. View inodes consumption

View space with the following command The inodes of the occupied file system consumes, if there are a large number of inodes available, it means that the large file takes up space, otherwise it may be that a large number of small files take up space.

#df -i /home

3. Find the directory that takes up a lot of space

View the space occupied by /home:

#du - Hs /home

View directories with more than 1000MB of space under /home:

#du | Awk '$1>2000'

4. Find out files that take up more space

Find files that take up more than 2000KB:

#find /home -size + 2000k

Find files between 500KB and 1000KB in size:

#find -type f -size +500k -and -size -1000k

5.Find out the nearest Modified or created files

If the file system is still normal yesterday, the space is full, so you need to find out which files have been updated and which ones are newly created to find and process them. Unusual large files. First “touch” a file, the timestamp is set to a relatively recent date according to the specific situation, and then use the find command to find a file that is newer than this file.

#touch -t 08190800 test

#find /home -newer test -print

6. Delete unused files such as logs and emails

Delete core, mbox, etc. files:

#find /-name core |  Xargs rm -rf

#find /-name mbox |  Xargs rm -rf Previous12Next Total 2 Pages

Copyright © Windows knowledge All Rights Reserved