Brother Bird's Linux private Cuisine Basics Study Book notes (9): Linux disk and File System Management (2)

Source: Internet
Author: User
Tags parent directory

The previous article mainly analyzed the Linux Ext2 file system Theoretically, this article mainly explains how to check the capacity of Linux file system and explain the connection files in Linux file system.

The DF and Du commands can be used to view the capacity of the disk and directory, and the DF command lists the overall disk capacity of the file system, and the DF command uses the DF [-ahikhtm] directory or file name. if the DF command does not add any parameters, the capacity and usage of all file systems within the system are listed by default. The DF command also needs to state that the DF command is a view of the overall use of the file system and therefore reads the information from Super block (see previous article), so the DF command executes very quickly.

The following is an example of using the DF command:


as you can see, although using the DF command to see the usage of the/etc directory, the DF command automatically parses the partition where the directory resides, and then enumerates the usage of that partition out. There's no confusion here, as long as the disk quota is not used, the capacity that the/etc directory can use is the capacity of the file system where the directory resides.

Well, if I was going to look at the file system capacity already occupied by the/etc directory, you have to use the Du command, which is used primarily to view the capacity of the directory. Unlike the DF command,thedu command goes directly to the file system to view all the file system data, so the execution time may be longer. About the du command or a little more, maybe the bird's book is not very clear, the du command displays the capacity of each subdirectory in the directory by default, and the total directory capacity displayed is sums the capacity of each subdirectory under that directory.

As an example:



There are a total of three subdirectories in the/home directory:/HOME/HW,/home/test_one,/home/fuchencong, their capacity (already counted as subdirectories) is 4k,52k,240k, and can be viewed to/home The directory itself (not the capacity of the operator directory) is 4k, so the final display of the/home directory capacity is 4k + 52k + 240k + 4k= 300k.

In addition, when using the du command, if you add the-s parameter, the displayed directory capacity will not be added to the capacity of the subdirectory, at this point only shows the capacity of the directory itself (and of course, the directory direct file) as shown in: The/home directory displays a capacity of 4k, which is the capacity occupied by the/home directory itself, not including the capacity occupied by its subdirectories.

Next explain the connection files in Linux, if you already understand the Linux Ext2 file system, then it is very easy to understand the connection file.

In the Linux operating system, the connection file is divided into two types, hard connection (actual connection) and symbolic connection. you can use the LN command to create a connection file, and the ln command is used by the LN [-SF] Source file destination file, if no parameters are added making a connection file is the default to create a hard connection, and if you add the-s parameter, it represents the creation of a symbolic connection file. What is the difference between a hard connection and a symbolic connection?

As already mentioned in the previous article, Linux reads a file, the first to find out the file name corresponding inode number in the directory block, if there are multiple filenames simultaneously corresponding to an inode number, then regardless of which file name is actually accessed to the same file, in fact, this is a hard connection. Simply put, a hard link simply creates a new associated record with a file name associated with an inode number in a directory. When more than one file name is associated to the same inode number, the data of the file can be accessed through any of these filenames, and the actual file data is eventually modified regardless of the file name that is used to modify the data. Similarly, when a file is deleted, the reference count in the inode is actually just 1, and the file data is not really deleted, only if the reference count in the inode is reduced to 0, the file data is actually deleted.

However, hard connections are limited because each file system has its own inode number, so the inode number for the file name in the directory entry can only be inode in the same filesystem. number, so hard connections can only be created for the same file system and cannot be established across file systems. And a hard connection cannot connect to the directory. Creating a hard connection to a catalog increases the complexity of the system environment, while creating a hard connection to a directory can easily cause loops. Hard connections to the directory are therefore not supported.

Linux also has a class of connections, called symbolic connections. Unlike a hard connection, a symbolic connection creates a separate file, except that the data read of the file is diverted to read the data it points to the file. Therefore, when the source file is deleted, the symbolic connection will "not be opened". And for a symbolic connection, its file length is the length of the filename of the file it refers to, because in the connection file, its contents are the "file name" of the target file.

The following is an example of a hard join and a symbolic connection:


The diagram clearly observes that Hard_link and test.file are associated to the same inode number, so the two files represent the same file, and the reference count is 2. The inode for the Symbol_link file is different from Test.file because Symbol_link is a standalone file, but it is a connection file to Test.file, and you can observe that the Symbol_link file length is 9 bytes. is actually test.file the file's filename length.

Finally, explain the number of connections to the directory. Each time a new empty directory is created, the number of connections for that new directory is 2. Why is it? First the directory itself occupies a connection, and then there is a special directory in the Directory ".", which also represents the directory, so the number of connections for this directory is 2. If you create a subdirectory in the new directory, the number of connections for that directory will be + 1. Because a new subdirectory has a special directory "..", which represents the parent directory, it also points to the directory, so the number of connections in this directory is +1.


This chapter is a summary of Linux commands:

DF, Du, Ln.


Brother Bird's Linux private Cuisine Basics Study Book notes (9): Linux disk and File System Management (2)

Related Article

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.