Linux delete files under the principle of

      1. Lniux under control files actually deleted counter

        LinuxIs linkthe number to control the deleted files. Only when a file does not exist any link, this file will be deleted. In general, each file has two link counters: i_countandi_link

        • i_countThe significance of the current number of files the user (or called) is
          when a file is referenced a certain process, the corresponding value will increase
        • i_nlinkThe significance of the number (the number of hard links) media connections
          When creating hard links files, this value will increase

        Can be understood as i_counta memory reference counter, i_nlinkis a reference to counter the hard drive

      2. rmCommand principle

        For the delete command rm, the disk is actually reducing the reference count i_nlink.

        Q : If a file is being called a process, but users execute rmthe file deletion, then what will be the result? When the user performs rmafter deleting the files, and then perform lsother file management commands, you can no longer find this file, but call this process to delete the file has continued to perform well, still able to correctly read and write from the file, This is why?

        A : rmOperation only the files i_nlinkreduced, if no other links i_nlinkon the 0. However, because the document is still being referenced process, therefore, when the corresponding file i_countis not 0, so the implementation of rmoperation, the system does not really delete this file, and only when i_nlink, and i_countare zero when the file will only be true delete. In other words, the process must lift the call to the file, in order to really delete.

        Q : When the file has not been called, is performed rmafter the operation, can recover deleted files do?

        A : rmOperation only the file i_nlinkis reduced, or is set to 0, the inode is actually a link removed at this time, and no entity (block block) file is deleted, this time, if the time to stop the machine work, data can be retrieved, if it continues to write data, the new data may be assigned to the block data block is deleted data file is truly recovered.

      3. Practical problems encountered

        Q : Web server disk space is not enough, in addition to all the mountain useless log or show lack of disk space, but du -shfound very little disk space usage, this is why? What causes insufficient disk space?

        A : Just delete command to delete a file i_nlink, but other processes are using these log files, apacheor tomatrestart these services Jiuhaola!

        original:
      4. https://www.cnblogs.com/cherishry/p/5886069.html

Guess you like

Origin www.cnblogs.com/tyk3201/p/12154637.html