Linux file Removal detailed

Source: Internet
Author: User



Linux file Removal detailed




1.1 Storage of Linux files

Linux will logically plan the disk into blocks when the file system is built,and the inode block corresponds to a number (the inode number ) for each block in block blocks . Unique in this file system , each inode block defaults to a size of $ 4K .


[Email protected] ~]# dumpe2fs/dev/sda1|egrep-i "Block count| Inode count|block size|inode Size "

DUMPE2FS 1.41.12 (17-may-2010)

Inode count:51200

Block count:204800

Reserved Block count:10240

Block size:1024

Inode size:128

[Email protected] ~]#


when you create a directory, the system allocates at least one inode block and block blocks, and the file system allocates at least one Inode and block blocks of file size when creating an archive ,

the Inode block stores the properties of the directory or file as follows:

  • Owner/group

  • Read/wirte/excute

  • Type

  • CTime atime mtime

  • Size

  • Flag (ID)

  • Pointer ( to the block corresponding to the file )

Block blocks Store the data contents of the file:

for Directories:block Stores the file structure under the directory and makes a link to the inode for each file name (indicated by the inode number).

for files:block stores real content data for files,

Note: The file's Block do not store file names inside


2.1 Reading of the file

Read File This is the block fast content to read the file, how did the system find the block?

to read /data/test.txt , for example:

first the system will go to / Find the file ancestor directory that is /data corresponding Inode # find inode block. inode The properties of this directory are recorded in the block, and the system verifies that the /data

the corresponding block number, find block blocks,block blocks in the file and the directory corresponding to the inode number, find /data/test.txt inode block, which satisfies the permission requirements, matches the block number that will get/data/test.txt, and finds the block blocks to read the contents.



650) this.width=650; "Width=" "height=" 393 "title=" 1.1 file read "style=" WIDTH:700PX;HEIGHT:393PX; "alt=" Wkiol1fm6ksjnis_aafngjcjlyq269.png "src=" Http://s5.51cto.com/wyfs02/M00/86/D7/wKioL1fM6kSjnIs_ Aafngjcjlyq269.png "border=" 0 "vspace=" 0 "hspace=" 0 "/>


So : file deletion is a record in the parent directory for the file that is deleted. To make the link four interrupts, the system naturally cannot find the file.



3.1 Binding file Permissions mutual authentication

Instance 1-1 Delete/home/redhat/data/test file

650) this.width=650; "title=" 2.png "alt=" Wkiom1fm61yjddptaaazhjf5xgu456.png "src=" http://s1.51cto.com/wyfs02/M00/ 86/d7/wkiom1fm61yjddptaaazhjf5xgu456.png "/>


The Redhat user has read and write execution permissions to the test file at this time

Perform the Delete

650) this.width=650; "title=" 3.png "alt=" Wkiol1fm62rtljrzaaaz3orxjaa106.png "src=" http://s2.51cto.com/wyfs02/M02/ 86/d7/wkiol1fm62rtljrzaaaz3orxjaa106.png "/>


Cannot delete without permission

File deletion just deletes a record of the file in the parent directory, the actual action object is the block block of the parent directory of the file, which requires WX permission on the parent directory.

650) this.width=650; "title=" 4.png "alt=" Wkiol1fm65azawcwaaaat9zfiau442.png "src=" http://s3.51cto.com/wyfs02/M02/ 86/d7/wkiol1fm65azawcwaaaat9zfiau442.png "/>


Give Data WX

650) this.width=650; "title=" 5.png "alt=" Wkiom1fm6-dijafuaabkui5rhdk898.png "src=" http://s4.51cto.com/wyfs02/M00/ 86/d7/wkiom1fm6-dijafuaabkui5rhdk898.png "/>


At this point, data does not have the test

Since a hard-link text was previously created for test, the test is not deleted and its data is still real.

Delete a hard link to the test, to really delete all the hard links that need to delete the file


650) this.width=650; "title=" 6.png "alt=" Wkiom1fm9cuje-7saadvcih3gw4994.png "src=" http://s1.51cto.com/wyfs02/M00/ 86/d8/wkiom1fm9cuje-7saadvcih3gw4994.png "/>


The Inode and block occupied by the file are not emptied, but are marked with unused tags, overwriting the flagged Inode and block when a file is written



The above deleted from the file system test, if there is a program in the call test then its disk space will not be freed, need to stop the program, free test storage space, so that the test is deleted.


4.1 In summary:



Linux implements file deletion by controlling the link number of the file.

Link refers to a hard-link file I-nlink

And the i-count of the process call

Files are deleted when only two colleagues are absent



650) this.width=650; "Width=" "height=" 313 "title=" 7.png "style=" width:600px;height:313px; "alt=" Wkiol1fm9glgikn_ Aadm6tau-jq055.png "src=" http://s1.51cto.com/wyfs02/M02/86/D7/wKioL1fM9gLgikn_AADM6Tau-JQ055.png "border=" 0 " Vspace= "0" hspace= "0"/>

You can use lsof-d to view the process that uses a file to end a process to free file space.


Linux file Removal detailed

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.