Impact of Linux cp mv rm ln command on inode and dentry

Source: Internet
Author: User

> For reprinting, please specify the Source: piao2010's blog, the drifting code. Thank you! Pai_^

> Link: Linux cp mv rm ln command impact on inode and dentry

When reading the File System Section of "Advanced Programming in UNIX environment", I found that I am not very clear about the concepts related to the file system.
First, we will introduce two basic concepts:
The first important concept, inode (Chinese name: Index node), contains most of the information about the file:
* Number of file bytes
* User ID of the file owner
* File group ID
* File read, write, and execution Permissions
* File timestamp. There are three timestamps: ctime refers to the last inode change time, mtime refers to the last change time of the file content, and atime refers to the last time the file was opened.
* Number of links, that is, how many directory items point to this inode
* File data block location

You can use the STAT command to conveniently view the inode file.

The second important concept is dentry (Chinese name: Directory item), which contains information such as the file name and pointer to inode, that is, the corresponding inode can be found through dentry, then, locate the block location of the file storage through inode.

If you want to learn more about file systems, refer to this article.

Next step: analyze the impact of Linux cp mv rm ln command on inode and dentry.
The experiment method is also very simple, as long as there is a Linux host, you can use the cp mv rm ln command to operate on the file, then use LS-il to view the file inode number, stat to view the inode information.

I directly gave the test conclusion:

CP command:
1) Allocate an unused inode number and add a new project to the inode table. (Note: if it is CP to an existing file, inode uses the inode Number of the target file to be overwritten. If you perform this operation on the so file of the Apache sharing module in the running state, segmentation fault will appear)
2) create a new directory item in the directory and point to inode in step 1;
3) copy the data to the block.

MV command:
A. If the target of the MV command is the same as that of the file system where the source file is located:
1) create a directory item using the new file name;
2) delete a directory item with the original file name;
Note: This operation does not affect the inode table (except the timestamp), nor does it affect the data location, and does not move any data. (Even if the music video is sent to an existing target file, the new directory item refers to the source file inode, which deletes the directory item of the target file first, so if you perform this operation on the shared module so file of the running Apache, there will be no problem, and the inode number of the new so file has changed)

B. If the object and the source file are in different file systems, CP and RM are used;

Rm command:
1) Reduce the number of links. If the number of links is 0, release inode (inode numbers can be reused );
2) If inode is released, data blocks are placed in the list of available spaces;
3) Delete directory items in the directory

Ln command:
A. Name of the hard link ln file name
Multiple directory items point to the same inode;
Use RM to delete hard-link files:
1) only reduce the number of links;
2) as long as a link exists in a file;
3) when the number of links is zero, the file is deleted.

B. Soft link (symbolic link) ln-s file name Link name
The content of the symbolic link is the file name it points;
The symbolic link file has its own inode;
If RM is deleted, only the linked file is deleted.

References:

Http://blog.csdn.net/rstevens/article/details/1824785

Http://iminmin.blog.51cto.com/689308/402660

Advanced Programming in UNIX environment

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.