Explanation of DF, Du and fsck commands in Linux file system

Time:2021-7-21

There are several common file systems in Linux environmentext3ext4xfsFrom centos7.0, the default file system is XFS, centos6 is ext4, and centos5 is ext3.

  • ext3:

The biggest difference between ext3 and ext4 is that ext3 takes a lot of time in fsck (more files, longer time), while ext4 takes a lot less time in fsck.

  • ext4:

Ext4 is the fourth extended file system (ext4). It is the log file system under Linux system and the successor of ext3 file system
Ext4 has a file system capacity of 1eb and a file capacity of 16TB, which is a very large number. This may not be important for the average desktop and server, but it’s very important for users of large disk arrays.
Ext3 only supports 32000 subdirectories at present, while ext4 cancels this restriction and theoretically supports an unlimited number of subdirectories.

  • xfs:

XFS is a very good log file system, which is designed by SGI company. XFS is known as the most advanced and scalable file system technology in the industry.
XFS is a 64 bit file system, which supports a single file system of 8eb minus 1 byte. The actual deployment depends on the maximum block limit of the host operating system. For a 32-bit Linux system, the size of files and file system will be limited to 16TB.

XFS is better than ext4 in many aspects. Ext4 is limited by disk structure and compatibility. Its scalability and scalability are not as good as XFS. In addition, after many years of development, XFS has done a better job in refining various locks!

Linux file system is a very important part of Linux system. First of all, let’s understand the directory structure of Linux file system.

  • /usr/bin/bin: store all the commands that users can execute
  • user/sbin/sbin: store commands that only root can execute
  • /home: the user’s default home directory or host directory
  • /proc: virtual file system
  • /dev: store social security documents
  • /lib: store the shared library needed by system program
  • /tmp: store temporary files
  • /etc: system configuration file
  • /var: contains frequently changing files, such as log files, scheduled tasks, etc
  • /usr: store all commands, libraries, manuals, etc
  • /mnt: the mount point of the temporary file system
  • /boot: kernel files and programs

1、 To view the usage of the file system hard disk:df

DF command is used to view the hard disk usage of each file system in Linux system, including the total capacity, used capacity and remaining capacity of the hard disk partition where the file system is located.

The basic format of DF command is as follows:

$DF [option] [directory or file name]

The common options and functions of DF command are as follows:

option effect
-a Display all file system information, including system specific / proc, / sysfs and other file systems;
-m Display capacity in MB;
-k The capacity is displayed in KB, which is the default unit;
-h Use our customary KB, MB or GB units to display capacity by ourselves;
-T Displays the file system name of the partition;
-i Instead of displaying the capacity of the hard disk, the number of inodes is displayed.

For example, execute the command:

$ df -h

Explanation of DF, Du and fsck commands in Linux file system

After the command is executed, the meaning of the printed result column information is as follows:

  • Filesystem: indicates which partition the file system is located in, so this column displays the device name;
  • Size: this column represents the total size of the file system;
  • Used: indicates the amount of hard disk space used;
  • Avail: indicates the remaining hard disk space;
  • Use%: hard disk space utilization. If the utilization rate is more than 90%, we need to pay more attention, because the lack of capacity will seriously affect the normal operation of the system;
  • Mounted on: the mount point of the file system, that is, the location of the directory where the hard disk is mounted

Let’s execute the following command:

$ df -h /etc

Explanation of DF, Du and fsck commands in Linux file system

In this case, the DF command will automatically analyze the partition of the directory and display the information about the partition. From this, we can know how much capacity can be used in this directory.

2、 Statistics of disk space occupied by directory or file:du

Du is a command to count the disk space occupied by a directory or file. The format of the Du command is as follows:

$Du [option] [directory or file name]

Options:

  • -a: displays the disk usage of each sub file. By default, only the disk usage of subdirectories is counted
  • -h: display disk usage in customary units, such as KB, MB or GB, etc;
  • -s: count the total disk usage, but do not list the disk usage of subdirectories and sub files

Implementation:$du -sh /etc

Explanation of DF, Du and fsck commands in Linux file system

3、 Detect and repair the file system:fsck

It is inevitable that the computer system will be abnormal due to some system factors or human error operation (sudden power failure). In this case, it is very easy to cause the file system crash, and even cause hardware damage. This is also the reason why we have been emphasizing that “the server must shut down the service before restarting”.

So, if the file system is damaged, is there any way to repair it? Yes, for some small problems, the fsck command can be used to solve them.

The fsck command is used to check the file system and try to fix errors that occur. The basic format of the command is as follows:

$fsck [option] partition device file name

option function
-a Automatically repair the file system without any prompt information.
-r Adopt the interactive repair mode, and ask before modifying the file, so that the user can confirm and decide how to deal with it.
-A (capital) Check all the file systems listed in the / etc / fstab configuration file.
-t File system type specifies the type of file system to check.
-C (capital) Displays a progress bar for checking the partition.
-f Forced detection, the general fsck command if there is no problem with the partition, it will not detect. If the detection is mandatory, it will be detected regardless of whether the problem is found or not.
-y Automatic repair, the same as – A, but some file systems only support – Y.

This command is usually used only when you are root user and there is a problem with the file system. Otherwise, if you use fsck command under normal conditions, it is likely to damage the system. In addition, if you suspect that there is a problem with a hard disk that has been formatted successfully, you can also use this command to check.

There is a risk in using fsck to check and repair the file system, especially when the hard disk error is very serious. Therefore, when a damaged file system contains very valuable data, be sure to back it up first!

It should be noted that when using the fsck command to modify a file system, the disk partition corresponding to the file system must be in the unloaded state. It is very unsafe to repair the disk partition in the mounted state, and the data may be damaged or the disk may be damaged.

Explanation of DF, Du and fsck commands in Linux file system

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]