How Linux files are deleted

Source: Internet
Author: User

Linux file Deletion principle:

Linux is controlled by the number of link to delete the file, only if a file does not exist any link, the file will be deleted.

In general, there are 2 link counters for each file: I_count and I_nlink.

The meaning of I_count is the number of users (or calls) of the current file, i_nlink the amount of media connections (number of hard links), which can be understood as I_count is the memory reference counter, and I_nlink is the reference counter for the disk.

When a file is referenced by a process, the corresponding number of i_count is incremented, and the corresponding I_nlink number is incremented when a hard link to the file is created.

For the Delete command RM, the actual reduction is the disk reference count I_nlink. There is a problem here, if a file is being called by a process and the user is performing an RM operation to delete the file, what will happen? When the user performs an RM operation to delete a file and then executes the LS or other file management commands, the file can no longer be found, but the process of invoking the deleted file continues to execute normally and the content can be read and written correctly from the file. Why is that?

This is because the RM operation only reduces the file I_nlink, if there is no other link i_nlink is 0, but because the file is still referenced by the process, so the file corresponding to the I_count is not 0, so even if the RM operation, but the system does not really delete the file, When only I_nlink and I_count are 0, the file is actually deleted. That is, you also need to dismiss the process's call to the file.

The above-mentioned I_nlink and I_count is the true condition of the file deletion, but when the file is not called, does the RM operation delete the file after the deletion can be retrieved?

Said before, RM Operation just reduce the file I_nlink, or 0, the actual is the file name to the Inode link deleted, at this time, and not delete the file entity (Block data block), at this time, if the machine to stop work, the data can be retrieved, If you continue to write data at this time, then when the new data may be allocated to the deleted data block blocks of data, this time, the file will be really recycled, then there is no way the gods.

How Linux files are deleted

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.