Linux file Properties
1. Overview of Linux Files
2. Inode Index Node
3. Block
4, the relevant face questions
5, Linux soft and hard connection
6. Soft Connection
7. Summary of File connection
8. Summary of directory Connection files
9, the difference between soft and hard connection
10. How to delete linux files
1. Overview of Linux Files
? The properties of files and directories in a Linux system include: Index node number (inode), file type and permissions, number of hard links, the user (owner) of the file or directory, the group to which the file or directory belongs (the group), the size of the file, the modified time of the file, the actual file name, or the directory name.
? Analysis of the results of Ls-lhi execution
2. Inode Index node
2.1 Basic Features
? When a disk (storage device) is partitioned into a ext4 system, two parts are generated: Inode and block (both have many).
? The Inode is the property of the file and the index of the file (the entity that points to the file), so the inode itself is size, the inode default size in the Centos5 series is 128 bytes, and the inode default size in the CENTOS6 series is 256 bytes.
? In addition to storing the file's attribute information, the Inode also holds pointers to the data blocks that are executed
? Block is used to hold the actual data, the common block size is 4K, its boot partition is 1 k, the other normal partition is 4K.
? The inode does not contain a file name because the file name does not belong to the properties of the files.
? The index node number representation is a string of numbers, like everyone's xxx number, is unique.
? When the system reads the file, it first finds the Inode number by its file name before it can read the contents of the file.
? Inode node number of the same file, mutual hard links, you can understand the same supermarket at different entrances.
? EXT3/EXT4 file system, a file occupies and only occupies one inode.
? EXT3/EXT4 file system, when a file is created, it consumes at least one inode and one block.
? If a file is large (such as high-definition), it needs to occupy multiple blocks, if a file is small (such as only 0.01K) then it will occupy a block, and the remaining space is wasted, that can not be stored in other things.
2.2 Viewing the size of inode and block
[Email protected] test]# dumpe2fs/dev/sda3 |egrep-i "inode size|block size"
DUMPE2FS 1.41.12 (17-may-2010)
Block size:4096
Inode size:256
2.3 Block
? Disk read data is read by block
? A file may occupy more than one block, but each block you read consumes a disk IO
? To improve disk IO performance, you need to read as much data as you can
? A block can only hold one file, no matter how big, assuming a block size of 4K, then store a 1K of files, the rest of the space can not be stored data, can only be wasted,
? Block is not the bigger the better, too big for small files will be wasted disk space, generally according to the business of file size selection, General CENTOS6 default is 4K
? Can change the size of the Inode and block when formatting
? Formatted command: Mkfs.ext4-b 2048-i 256/dev/sdb where-B is the size of the specified block,-I is the size of the specified inode
2.4 Related face questions
? Topic
Disk space is full, there are 3 kinds of things that can't be written in.
The first: Block full, can be viewed with df-h. Look use%, delete some files can
The second type: The Inode is full, you can use Df-i to view, see iuse%, delete some small (unused) files can be
Third: The number of hard links is 0, the number of process calls is not 0
2.5 Linux soft and hard connection
2.5.1 the creation process of hard links
? ln source file Destination file
2.5.2 hard-Link schematic diagram
2.5.3 Features of hard connection
? Multiple files share the same index node without taking up real space
? A hard link is a multiple entry for a file (which can be understood as a supermarket with multiple entrances)
? As long as the number of connections is not 0, the file exists, so the hard link can prevent the file from being deleted accidentally
? Deleting a source file or any one of the hard links, the file entity is not deleted, and the file entity is deleted only if the source file and all its hard links are deleted at the same time
? Hard-link files are normal files that can be deleted with the RM command
? For a static file (that is, a file that is not called by the process), the file is deleted when the i_link number is 0 o'clock (the third column of the I_link View method Ls–l)
2.6 Soft Connection
2.6.1 the process of creating a soft connection
? Ln-s Source File Destination file
Schematic diagram of the 2.6.2 soft connection
Features of the 2.6.3 soft connection
? A soft connection is similar to a shortcut under Windows (you can view its point by Readlink)
? The soft connection still exists when the source file is deleted, but the content pointing to the source file cannot be accessed
? Soft connection is usually a red background flashing hint
? Soft connections and source files are different types of files, files are different, inode node numbers are also different
? The type of soft connection is L and can be removed with the RM command
2.7 Summary of file connections
? Deleting soft connection files has no effect on source files and hard-linked files
? Removing hard-link files has no effect on source files and soft-connect files
? Deleting a source file has no effect on hard-link files, but causes the soft connection file to fail with a flashing hint on the red background
? Hard links and source files have the same inode number, can be considered the same file, or can be understood as a file with multiple portals
? Soft connections and source files have different inode numbers, are different files, soft connections are shortcuts to source files, and locations with source files point to
? Graphic understanding of soft and hard connections
2.8 Summary of directory connection files
? The directory is not available to create a hard link, but you can create a soft connection
? Hard links to directories cannot span the file system (understood from the principle of hard links)
? There is a hard link under each directory. and a hard link to the parent directory.
? A subdirectory is created under the parent directory, and the number of hard links in the parent directory is 1 (because there is one in the subdirectory: to the parent directory), but creating the file below will not increase the number of hard links in the parent directory
2.9 Differences between soft and hard connections
? Hard link files and source files share an inode number, and the soft connection file and source file have different inode numbers
? The process of creating a hard link and a soft connection is different (create a hard link ln source file destination file to create a soft connection ln-s source file destination file)
? Delete source files, hard links can be accessed, soft connections cannot be accessed
? The catalog can create a soft connection and cannot create a hard link
? Soft connections cannot modify the name of the source file, hard links can be modified
? Soft connections can be cross-system, hard links can not
? Deleting a soft and hard connection does not affect the source file, remove the hard links, reduce the number of connections by 1
2.10 How to delete linux files
? Deletion of Linux files is controlled by two things: I_link (number of hard links) and I_count (number of calls to process), only if both values are 0 o'clock the file is deleted
? Using RM to remove the process that makes I_link 0 Restart the use of this file makes I_count 0
? Diagram of the Linux removal principle
Note: Only I_link and I_count values of 0 files will be deleted.
Permission to delete a file is dependent on the parent directory's control and the permissions of the file province
Linux file properties