Linux disk and file system (1) ------- inode, block, df and du, soft and hard links

inode: record the attributes of the file, one file occupies one inode
block : actually records the content of the file. If the file is too large, it will occupy multiple blocks.
Superblock: This is where information about the entire filesystem is recorded.


The data block is where the data of the file content is placed.
The block sizes supported in the Ext2 file system are 1k, 2k, and 4k.
When formatting, the block size is fixed. And each block will have a number to facilitate the recording of inodes.

The information recorded by the superblock mainly includes:
• Total amount of blocks and inodes
• Number of unused and used inodes/blocks
• Size of block and inode (block is 1, 2, 4K, and inode is 128 bytes)
• The mount time of the filesystem, the time when the data was last written, the time when the disk was last checked (fsck) and other file system related information
• A valid bit value. If the file system is mounted, the valid bit is 0. If it is not mounted, the valid bit is 1.


The block bitmap records the used and unused block numbers, and the inodebitmap records the used and unused inode numbers!


Disk directory and capacity

We know that the sorting data of the disk is in the superblock, but the capacity of each individual file is recorded in the inode.

df : List the overall disk usage of the filesystem
du : evaluate the disk usage of the file system (commonly used to estimate the capacity of a directory)

A few common options to remember in df
-h : Display the size in the usual way. Such as 10M, 10G, 10T.





from   

-a : List all file and directory sizes
-h : display in human-readable volume format
-s : list the total, not the capacity of each individual directory
-k : display the capacity in kbytes






ln
There are two kinds of links under Linux, one is a file similar to the Windows shortcut function, which allows you to quickly link to the target file (or directory); the other is to generate a new link through the inode link of the file system. filename instead of generating a new file! This is called an entity link (hard link).

Hard Link (physical link, hard link or actual link)
•Each file will occupy an inode, and the content of the file is pointed to by the inode record;
• To read the file, you must point to the correct inode number through the file name recorded in the directory to read.


So to put it simply: hard link just adds a file name to a certain inode number in a certain directory.

, assuming that my system has a crontab, which is an entity link to /etc/crontab, that is to say, the two file names are linked to the same inode, and naturally all the relevant information of the two file names will be exactly the same (except the file name). The actual situation can be as follows:




Entity links cannot span Filesystems and cannot link directories.

Symbolic Link (symbolic link, aka shortcut)
Symbolic link is to create a separate file, and this file will make the data read point to the file name of the file to which it is linked! Since only the file is used as the pointing action, when the source file is deleted, the file of the symbolic link will "cannot be opened", and it will keep saying "cannot open a certain file! '. In fact, I just can't find the original "file name"!





Number of links to directories
What will be the default number of links when creating a directory? Let's think about it, what at least can exist in an "empty directory"?
Existing . and .. these two directories, then, when we create a new directory named /tmp/testing, there will basically be three things, that is:
n/tmp/testing
n/tmp/testing/.
n/tmp/testing/..
And where /tmp/testing and /tmp/testing/. are actually the same! Both represent the directory, and /tmp/testing/.. represents the directory /tmp, so when we create a new directory, the number of links in the new directory is 2, and the number of links in the previous directory is 1 will be added.




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325818822&siteId=291194637