Teach you how to clean up the large files released at the end of the application

Source: Internet
Author: User

Teach you how to clean up the large files released at the end of the application

Directly,



Explanation:


1. The size of du is different from that of df.


2. lsof searches for files marked with delete and sorts the files by size.


3. Find the PID fd of a large file


4. Clear large files




We all know that regular log clearing is used> rather than directly rm


The reason is simple because the system is in use. Even if you delete a file, fd still points to the same inode, but you have deleted the Directory Index node. In order to make the application run normally, the system will not release the file used for writing, and it will still exist on the disk.


What is the principle?


It is easy to implement with exec.


Exec can specify a file to be written, a file to be read, and the location of the file can be tracked)


Write one (for writing) now ):


[Public @ CNSZ040588 ~] $ Exec100>/tmp/ForWrite.txt [public @ CNSZ040588 ~] $ Ls-l/proc/$/fdtotal0lrwx ------ 1publicusr0164Apr2022: 140->/dev/pts/11lrwx ------ 1publicusr0164Apr2022: 141->/dev/pts/11l-wx ------ restart: 35100->/tmp/ForWrite.txt lrwx ------ 1publicusr0164Apr2022: 132->/dev/pts/11lrwx ------ average: 14255->/dev/pts/11 [public @ CNSZ040588 ~] $ Ls/tmp/ForWrite.txt [public @ CNSZ040588 ~] $ Echo "Good"> & 100 [public @ CNSZ040588 ~] $ Cat/tmp/ForWrite.txt Good [public @ CNSZ040588 ~] $ Exec100 <&-[public @ CNSZ040588 ~] $ Ls/tmp/ForWrite.txt [public @ CNSZ040588 ~] $ Ls/proc/$/fd012255



Original article: Teach you how to clean up the large files released at the end of the application

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.