Article Title: detailed analysis of the use of the Linuxdu command. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The Linux du command is used to view the space used. However, unlike the df command, the Linux du command is used to view the space used by files and directory disks. It is also different from the df command, here we will introduce the Linux du command.
Du: query the disk space used by an archive or directory
A: displays the disk space occupied by all directories and each file in the second directory.
B: The size is represented by bytes (the default value is k bytes)
C: add the total value (default)
S: only display the total size of each file
X: only calculate the files of the same file system.
L: Calculate the size of all files
Common command: du? A
Operation Details
Reference
The command du can display the disk space occupied by all files in each directory in the unit of subdirectories in the specified directory. For example:
# Du-h/etc
104 K/etc/defaults
6.0 K/etc/X11
8.0 K/etc/bluetooth
4.0 K/etc/gnats
52 K/etc/isdn
388 K/etc/mail
68 K/etc/mtree
2.0 K/etc/ntp
38 K/etc/pam. d
44 K/etc/periodic/daily
6.0 K/etc/periodic/monthly
42 K/etc/periodic/security
16 K/etc/periodic/weekly
110 K/etc/periodic
6.0 K/etc/ppp
318 K/etc/rc. d
2.0 K/etc/skel
130 K/etc/ssh
10 K/etc/ssl
1.7 M/etc
The-h parameter is used to display the human-readable format. In the application, we can use the "du" command to check which directory occupies the most space. However, the output result of du is usually very long. We can add the-s parameter to omit the subdirectories in the specified directory, and only display the total combination of the directories:
# Du-sh/etc
1.7 M/etc
When viewing the usage of the Directory, we can export the output results to the sort command for sorting to know which file has used the most space:
# Du/etc | sort-nr | more
1746/etc
388/etc/mail
318/etc/rc. d
130/etc/ssh
110/etc/periodic
104/etc/defaults
68/etc/mtree
52/etc/isdn
44/etc/periodic/daily
42/etc/periodic/security
38/etc/pam. d
16/etc/periodic/weekly
10/etc/ssl
8/etc/bluetooth
6/etc/ppp
6/etc/periodic/monthly
6/etc/X11
4/etc/gnats
2/etc/skel
2/etc/ntp
The-nr parameter of sort indicates that reverse sorting is performed by numerical sorting. Because we want to sort the directory size, we cannot use the size output of human-readable, otherwise, the directory size may contain letters such as K and M, which may result in incorrect sorting.
Have you understood the differences between the Linux du command and the Linux df command.