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