View the file and folder size under Linux. Use df and du command to introduce

  

df can view the primary folder size, usage ratio, file system and its mount point, but can't do anything about the file. Du can view the size of files and folders.

The two are very effective. For example, use df to see which level of the directory is too large, and then use df to view the size of the folder or file, so you can quickly determine the crux.

The following is a brief introduction

The df command can display the available space and usage of all current file systems. Please see the following example:

Code:

[yayug@yayu ~]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 3.9G 300M 3.4G 8% //dev/sda7 100G 188M 95G 1% /data0 /dev/sdb1 133G 80G 47G 64 % /data1 /dev/sda6 7.8G 218M 7.2G 3% /var /dev/sda5 7.8G 166M 7.2G 3% /tmp /dev/sda3 9.7G 2.5G 6.8G 27% /usr tmpfs 2.0G 0 2.0G 0 % /dev/shm

The parameter -h indicates the output of "Human-readable", that is, the file system size is easy to read using GB, MB, etc.

The first field (Filesystem) and the last field (Mounted on) of the above command output are the file system and its point of entry. We can see that the partition /dev/sda1 is hung in the root directory.

The next four fields, Size, Used, Avail, and Use%, are the partition's capacity, used size, remaining size, and percentage used. Under FreeBSD, when the hard disk capacity is full, you may see that the percentage used has exceeded 100%, because FreeBSD will leave some space for root, so that when the file system is full, you can still write things to the file system. For management.

du: Query disk usage space of files or folders

If there are many files and folders in the current directory, use the command without parameter du to list all files and folders in a loop. The space used. This is not good for viewing where the place is too large, so you have to specify the number of layers in the deep directory, the parameter: --max-depth=, this is an extremely useful parameter! As follows, pay attention to the use of “*”, you can get the size of the file space.

Reminder: The command has always been more complicated than Linux FreeBSD, its du command specifies the number of layers in the in-depth directory is simplified than Linux. Is -d.

The code is as follows:

[root@bsso yayu]# du -h --max-depth=1 work/testing 27M work/testing/logs 35M work/testing [root@bsso yayu ]# du -h --max-depth=1 work/testing/* 8.0K work/testing/func.php 27M work/testing/logs 8.1M work/testing/nohup.out 8.0K work/testing/testing_c.php 12K work/testing/testing_func_reg.php 8.0K work/testing/testing_get.php 8.0K work/testing/testing_g.php 8.0K work/testing/var.php [root@bsso yayu]# du -h --max-depth =1 work/testing/logs/27M work/testing/logs/[root@bsso yayu]# du -h --max-depth=1 work/testing/logs/* 24K work/testing/logs/errdate.log_show. Log 8.0K work/testing/logs/pertime_show.log 27M work/testing/logs/show.log

It is worth noting that I saw an article for the similarities and differences between du and df commands: "du df difference causes files System false positives are resolved.

du stat file size add df stats block usage

If a process opens a large file, this large file is directly rm or mv, then du will be updated The statistical value, df will not update the statistical value, or that the space is not released. Until this process of opening a large file is killed by Kill.

As a result, when the files under /var/spool/clientmqueue are deleted regularly, the space is not released if the process is not killed.

After killing the process with the following command, the system is restored. Fuser -u /var/spool/clientmqueue

Copyright © Windows knowledge All Rights Reserved