Df and du commands using basic tutorials

  
 

df command: Determines the size of allocated space in the file system through unallocated space in the file system. For example, if there are 8192 512-byte blocks in a file system and 4096 blocks are not allocated, the allocated space is 4096 512-byte blocks. Allocated Space = Total Space - Unallocated space is calculated based on the file system population, so the df command is the most reliable command to report file system space usage. The du command is a file-oriented command that calculates the space allocated to a specified file or directory. The du command must follow the destination parameter and cannot isolate the file system. For example, running the # du /command will calculate the space allocation information for all files in the /file system. This includes all /files of the /file system and files of other file systems installed under /, such as /tmp, /var and /usr. You can use the du command with the -x argument to restrict operations only within the file system. But sometimes it will lead to incomplete output. The du command only calculates the space occupied by the file. Does not calculate the space occupied by the file system metadata, such as inodes, inode maps, or disk maps. The du command only calculates the storage space occupied by those files that can be accessed. There are two cases. The du command does not calculate the space that has been allocated to the file. Case1: The file is hidden. For example, if a file is stored in the /bobby directory and then the file system is installed in the /bobby directory, the du command will not calculate the storage space occupied by the files in the /bobby directory. Case 2: The file was opened by another application, and the file was deleted. In this case, the storage space occupied by the file will remain in the assigned state until all access to this file is closed. Since there is no relevant record for this file in the directory, the du command will not calculate the allocated space of this file. However, the df command will calculate the allocated space. The operation of the two commands

is as follows:

df command detailed usage

a: Display all file systems and disk usage of each partition i: Display the usage of i-nodes k: size is represented by k (default) t : Display all partition disk usage of a file system x: Display all partitions of a file system disk usage T: Display the file system name of each partition. Common command: df -hi reference example: # Df -hFilesystem Size Used Avail Capacity Mounted on/dev/ad0s1a 1.9G 389M 1.4G 21% /devfs 1.0K 1.0K 0B 100% /dev/dev/ad0s1d 989M 54K 910M 0% /tmp/dev/ad0s1f 4.8G 3.8G 657M 86% /usr/dev/ad0s1e 1.9G 149M 1.6G 8% /var/dev/ad0s1g 26G 890K 24G 0% /volume2/dev/da0s1d 325G 261G 38G 87% /volume1 We added the parameter -h to use "Human" -readable" output, that is, using GB, MB, etc. in the file system size Read format. The first field and the last field of the above command output are the file system and its mount point. We can see that the partition /dev/ad0s1a is hung in the root directory. We mentioned in the previous section that ad represents the IDE's hard disk, and s1 represents the first major sector. I also have a SCSI hard drive, which is coded da, which has a large capacity and is mainly used to store data. Devfs is a special file system. This file system is not a real disk, but a virtual file system used by FreeBSD to manage system hardware devices. The next four fields, Size, Used, Avail, and Capacity, are the partition's capacity, used size, remaining size, and percentage used. When the hard drive 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 to the file system for management. . In addition, we can also use the parameter -i to see the current file system inode usage. Sometimes there is space in the file system, but if there are not enough inodes to store the information of the file, the new file will not be added. # df -ihFilesystem Size Used Avail Capacity iused ifree %iused Mounted on/dev/ad0s1a 1.9G 389M 1.4G 21% 20495 262127 7% /devfs 1.0K 1.0K 0B 100% 0 0 100% /dev/dev/ad0s1d 989M 62K 910M 0% 24 141286 0% /tmp/dev/ad0s1f 4.8G 3.8G 657M 86% 311439 348015 47% /usr/dev/ad0s1e 1.9G 149M 1.6G 8% 1758 280864 1% /var/dev/ad0s1g 26G 890K 24G 0% 12 3532786 0% /volume2/dev/da0s1d 325G 261G 38G 87% 707277 43311409 2% /volume1 We can see that the number of used inodes in the root directory is 20495, and there are 262127 available inodes. Little reminder remember what is an inode? The so-called inode is used to store the basic information of files and directories, including time, file name, user and group. When partitioning a sector, the system first makes a bunch of inodes for later use. The number of inodes is related to the total number of files and directories that can be created in the system. If most of the files to be saved are small, there will be more files in the same size hard disk, which means more inodes are needed to hang files and directories.

du: Query disk usage space of file or directory

a: Display disk space occupied by each file in all directories and sub-directories b: size is represented by bytes (default value k bytes) c: last plus total (default) s: only show the total size of each file x: only calculate files belonging to the same file system L: calculate all file size common commands: du -a reference Example: # du -h /etc104K /etc/defaults6.0K /etc/X118.0K /etc/bluetooth4.0K /etc/gnats52K /etc/isdn388K /etc/mail68K /etc/mtree2.0K /etc/ntp38K /etc /pam.d44K /etc/periodic/daily6.0K /etc/periodic/monthly42K /etc/periodic/security16K /etc/periodic/weekly110K /etc/periodic6.0K /etc/ppp318K /etc/rc.d2.0K /etc /skel130K /etc/ssh10K /etc/ssl1.7M /etc We use the -h parameter to display the human-readable format. When applying, we can use the du command to see which directory takes up the most space. However, the output of du is usually very long. We can add the -s parameter to omit the subdirectory under the specified directory, and only display the total of the directory:

Copyright © Windows knowledge All Rights Reserved