Linux access to disk usage commands (DF du) __linux

Source: Internet
Author: User
Tags disk usage oracle database

1. Preface

In embedded devices, hard disk space is very limited, when it comes to the process of often write log, you need to consider the size of the log and delete, or soon the hard disk is full, causing the log program crashes. In order to capture the hard disk is full of abnormal scenes, we need to write in the log process to determine the use of hard disk space, according to the use of hard disk, you can judge whether it is full. If it's going to be full, give a warning. This will prevent the program from crashing. First look at the Linux access to the hard disk and directory size commands, and finally summed up the STATFS structure and functions.

2, DF command

Linux can be used with DF command to obtain the use of hard disk, through the man can get the details of the DF command. The parameters commonly used by the DF command are:

A: Displays all the file systems and the disk usage scenarios for each partition
I: Show the amount of i-nodes used
K: size is represented by K (default value)
T: Displays all partition disk usage for one file system
X: Displays all partition disk usage that is not a file system
T: Displays the name of the file system to which each partition belongs
Common commands: Df-hi

Examples of screenshots are shown below

3. du command

The du command is used to query the disk usage space of the file or directory, and the man gets a detailed description of the du command. The commonly used command parameters are as follows:
A: Displays the disk space for each file in all directories and second directories
B: The size is represented by bytes (the default value is k bytes)
C: Last plus total (default)
S: Show only the sum of each file size (summarize)
x: Only the files of the same file system are counted
L: Calculate the size of all files
Common commands: Du-ah

Examples are shown in the following illustration:

To sum up: the difference between DF and Du, du view the directory size, DF View disk usage.

The DU-SH command accumulates the total number of blocks used by the filesystem by adding the number of blocks used in all directories, symbolic links, and files in the specified file system;
The DF command obtains the total block number and the remaining block number by viewing the file system disk block allocation graph.
The file system allocates some of these disk blocks to record some of its own data, such as I nodes, disk maps, indirect blocks, super blocks, and so on. This data is not visible to most user-level programs, often called Meta data.
The du command is a user-level program that does not consider meta data, while the DF command looks at the file system's disk allocation graph and considers meta data.

Therefore, in normal circumstances, the used space of DF calculation is slightly larger than that of the DU calculation.

2, under abnormal circumstances, DF calculation of used space will be much larger than DU.

This is also the problem that I encountered before, DF View results File system 100% used, and du the result is still 6GB idle, on such a problem hardware manufacturers a support incredibly do not know how to explain, this is also let me curious to come back to check out the reason for the night, the results of Google has a.

The reason is that Du is used in the computational space based on the file name, directory name, and DF is used to compute the space using the disk block usage.

When an application is writing a large file, we RM or MV This file (Unix is allowed to do this, Windows is silly on this point), the application will occupy the handle and write the disk directly according to the disk location referred to by the handle, without checking that the file is deleted.

Therefore, the above problems will arise. At the Oracle level, this can happen because Oracle, for some reason, is generating a large trace file that could result in a directory full of Oracle, and if the trace file is directly RM or MV out of the way, it will find that space is not released. This may lead to Oracle database down machines.

Workaround: Use the "> tracefile.trc" command to clear the file, if you need to keep the trace file to facilitate postmortem analysis, you can use CP to copy the file to another place, and then empty the original file.

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.