Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux basic part Learning-- the principle of linux File deletion

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Principle of file deletion

Click to view knowledge of soft links and hard links

Link counter

Linux controls file deletion through the number of link

  A file will be deleted only if no link exists.

  generally speaking, each file has two link counters: i_count and i_nlink

  i_count   memory reference counter

The number of current file users (or called) of  . When a file is referenced by a process, the number of corresponding i_count will increase.

  i_nlink   disk reference counter

The number of   media connections (the number of hard links). When you create a hard link to a file, the corresponding number of i_nlink increases

Delete the command rm

Rm is actually reducing the disk reference count i_nlink

Rm deletes common sense

What happens if a file is being called by a process and the user performs a rm operation to delete the file?

   when the user executes the rm operation to delete the file, and then executes ls or other file management commands, the file can no longer be found, but the process of calling the deleted file continues to execute normally and can still read and write correctly from the file.

   this is because the rm operation only reduces the i_nlink of the file, and if there are no other links, the i_nlink will be 0; but because the file is still referenced by the process, the corresponding i_count of the file is not 0.

The condition that the file is actually deleted is i_nlink=0 and i_count=0

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report