Describes CP, MV, and RM behaviors from the inode perspective

Source: Internet
Author: User

 

 

1 Overview

We often think that a directory is a container with directories and files. In fact, a directory is a ing table. People use file names to reference files, while computers use inode numbers to reference files. The directory is the ing table between the file name and inode number.

2 CP and inode

Usage:

CP [Option] File [file 2 | file 3...] target option:-I asked-R to recursively copy the entire directory tree-P before overwriting the file to reserve the permission, owner, and the combination of Timestamp-a-r and-P.

The CP command must always have at least two parameters. If more than two parameters are given, all parameters except the last parameter will be parsed as source files.

The target affects CP behavior:

If the target is a directory, the copied file will be placed in it.
If the target object is an object, the Copied object will overwrite the target object.
If the target does not exist, the copied file will be renamed as the target name.

 

Inode:

1) assign an unused inode number and add a new project to the inode table.
2) create a row in the directory ing table and associate the file name with the inode number.

 

3 mV and inode

The behavior of the MV is the same as that of the CP. Except for the MV, the source file disappears.

When a file MV is generated, the actual content of the file is not transferred, regardless of the inode project or the data on the hard disk. Only the directory ing table is transferred.

Two cases:

1) the target file is in the same file system as the original file.
A) create a new row in the directory ing table.
B) Delete the original directory line with the source file name

2) If the target file system is different
Music videos are copied and deleted.

Case:

[root@think water]# ll -i w3496568 -rw-r--r-- 1 root root 17 09-25 15:12 w[root@think water]# mv w /home/water[root@think water]# cd /home/water[root@think water]# ll -i w3496568 -rw-r--r-- 1 root root 17 09-25 15:12 w

The inode number is still the same. The data on the file system is not transferred, and the inode table is not changed, but the timestamp on it is updated.

 

4 RM and inode

Rm-r deletes the Directory and its content.
Rm-F deletes the Directory and its content.

 

Inode analysis:

1) decrease the link count to release the inode number. This inode number can be reused.
2) mount the data block to the available space list
3) Delete related rows in the directory ing table

 

However, the underlying data is not actually deleted, but when the data block is used by another file, the original data will be overwritten.

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.