When the disk size exceeds the standard, an alarm is triggered. 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.
When the disk size exceeds the standard, an alarm is triggered. 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 following is a brief introduction.
The df command can display the available space and usage of all file systems. See the following example:
The following is a code snippet:
[Yayug @ yayu ~] $ Df-h
Filesystem 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.5 GB 6.8G 27%/usr
Tmpfs 2.0G 0 2.0G 0%/dev/shm
The-h Parameter indicates that "Human-readable" is used for output, that is, the file system uses readable formats such as GB and MB.
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: queries the disk space used by files or folders.
If there are many files and folders in the current directory, you can use the command without the du parameter 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 has always been a more complex command than linux, uses the du command to specify the number of layers in the directory, which is simpler than linux.
The following is a code snippet:
[Root @ bsso yayu] # du-h -- max-depth = 1 work/testing
27 M work/testing/logs
35 M work/testing
[Root @ bsso yayu] # du-h -- max-depth = 1 work/testing /*
8.0 K work/testing/func. php
27 M work/testing/logs
8.1 M work/testing/nohup. out
8.0 K work/testing/testing_c.php
12 K work/testing/testing_func_reg.php
8.0 K work/testing/testing_get.php
8.0 K work/testing/testing_g.php
8.0 K 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.log
8.0 K work/testing/logs/pertime_show.log
27 M work/testing/logs/show. log
It is worth noting that I have seen an article about the similarities and differences between the du and df commands: Solving false positives caused by the difference in du df.
Du statistics file size Addition
Df statistics block usage
If a process directly loses rm or mv when opening a large file, du updates the statistical value and df does not update the statistical value, I still think 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
View the size of the linux File directory and the number of files contained in the folder
Total statistics size
Du-sh xmldb/
Du-sm * | sort-n // count the current directory size and sort the directory size.
Du-sk * | sort-n
Du-sk * | grep guojf // view the size of a person
Du-m | cut-d "/"-f 2 // read the text before the second character
View the number of files in this folder /*
Du xmldb/
Du xmldb/* | wc-l
40752
Explanation:
Wc [-lmw]
Parameter description:
-L: number of rows
-M: The number of characters.
-W: How many words
Linux: ls displays the file size in the unit of K, M, and G.
# Man ls
......
-H, -- human-readable
Print sizes in human readable format (e.g., 1 K 234 M 2G)
......
# Ls
Cuss. war nohup. out
# Ls-l
Total 30372
-Rw-r -- 1 root 31051909 May 24 10:07 cuss. war
-Rw ------- 1 root 0 Mar 20 13:52 nohup. out