In Linux, the df and du commands for viewing files and folders will trigger an alarm when the disk size exceeds the standard. In this case, it is wise to master the df and du commands. Df allows you to view the size, usage ratio, file system, and its mount point of a level-1 folder, but there is nothing to do with files. Du allows you to view the file and folder size. They are very effective when used in combination. For example, you can use df to check which level directory is too large, and then use df to view the size of the folder or file, so that you can quickly determine the crux of the problem. The df command at www.2cto.com briefly introduces the available space and usage of all file systems. See the following example: the following code snippet: [yayug @ yayu ~] $ Df-hFilesystem Size Used Avail Use % Mounted on/dev/sda1 3.9G 300 M 3.4G 8% // dev/sda7 100G 188 M 95G 1%/data0/dev/sdb1 133G 80G 47G 64%/data1/dev/sda6 7.8G 218 M 7.2G 3%/var/dev/sda5 7.8G 166 M 7.2G 3%/tmp/dev/sda3 9.7G 2.5G 6.8G 27%/usrtmpfs 2.0G 0 2.0G 0%/dev/shm www.2cto.com parameter-h indicates the use of "Human-readable" output, that is, the size of the file system is in the format of GB, MB, and other readable formats. The first field output (Filesystem) and the last field (Mounted on) are respectively the File System and Its mount point. We can see that the/dev/sda1 partition is mounted under the root directory. The following four fields: Size, Used, Avail, and Use % are the capacity, Used Size, remaining Size, and percentage of the shard. In FreeBSD, when the hard disk capacity is full, you may see that the percentage used exceeds 100%, because FreeBSD will leave some space for the root user to make the root user full in the file system, you can also write something to the file system for management. Du: disk space used to query files or folders if there are many files and folders in the current directory, you can use the command without the parameter du to list the space used by all files and folders cyclically. This is not good for checking whether the location is too large. Therefore, you must specify the number of layers in the directory. The parameter is -- max-depth =, which is a very useful parameter! As shown in the following figure. Use "*" to obtain the space used by the file. reminder: FreeBSD, which is always more complex than linux, uses the "du" command to specify the number of layers in the directory, which is simpler than that in linux. It is-d. The following code snippets are available at www.2cto.com: [root @ bsso yayu] # du-h -- max-depth = 1 work/testing27M work/testing/logs35M work/testing [root @ bsso yayu] # du-h -- max- depth = 1 work/testing/* 8.0 K work/testing/func. php27M work/testing/logs8.1M work/testing/nohup. out8.0K work/testing/testing_c.php12K work/testing/testing_func_reg.php8.0K work/testing/testing_get.php8.0K work/testing/testing_g.php8.0K work/testing/var. php [root @ bsso yayu] # du-h -- max-depth = 1 work/testing/logs/27 M work/testing/logs/[root @ bsso yayu] # du- h -- max-depth = 1 work/testing/logs/* 24 K work/testing/logs/errdate. log_show.log8.0K work/testing/logs/pertime_show.log27M work/testing/logs/show. log www.2cto.com is worth noting that I saw an article about the similarities and differences between du and df commands:
The following references in resolving false positives caused by du df differences in file systems:
############### Receive an alarm today, linux space usage> 95% [root @ aus1ap04 clientmqueue] # df-k Filesystem 1K-blocks Used Available Use % Mounted on/dev/cciss/c0d0p2 10080520 9112968 455484 96%/none 1977584 0 1977584/ dev/shm/dev/cciss/c0d0p5 28842748 6706924 20670700 25%/u01/dev/cciss/c0d0p6 26850172 683148 24803108 3%/u02 www.2cto.com but use the du-kxs check, root directory usage is 80% du statistics file size addition df statistics block usage if a process opens a large file, this large file is directly r If m or mv is dropped, du updates the statistical value, df does not update the statistical value, or the space is not released. Until the process of opening a large file is killed. The problem we encountered was that we deleted the files under/var/spool/clientmqueue on a regular basis, but did not kill the process, so the space was never released. Use the following command to kill the process and restore the system. Fuser-u/var/spool/clientmqueue ############### du statistics file size addition df statistics block usage if one process is in when opening a large file, if this large file is directly deleted by rm or mv, du will update the statistical value, df will not update the statistical value, or think that the space is not released. Until the process of opening a large file is killed. In this way, when files under/var/spool/clientmqueue are deleted regularly, if the process is not killed, the space is never released. Use the following command to kill the process and restore the system. Fuser-u/var/spool/clientmqueue