In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of what the concept of du in linux is, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on the concept of du in linux. Let's take a look at it.
In linux, the full name of du is "Disk Usage", which is a command to count the disk space occupied by directories or files, and the syntax is "du [options] [directory or file name]". The du command supports a variety of options: 1, "- h", which can display the size in readable units; 2, "- s", which can display the total size of the directory; 3, "- d", and so on.
The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
Linux du command
Du is an acronym for Disk Usage and is one of the most popular commands on Linux. Du is a command that counts the disk space occupied by directories or files.
The format of the du command is as follows:
Du [option] [directory or file name]
Common options are as follows:
-a: displays all files and folder sizes in the directory
-h: displays the size in readable units such as Kb, Mb, Gb, etc.
-- si: similar to the-h option, but the calculation is based on 1000 instead of 1024
-s: displays the total size of the directory
-d: is an abbreviation for the-- max-depth=N option, indicating which layer directory it goes deep into. If it exceeds the specified number of layers, it will be ignored.
-c: in addition to displaying the directory size, an additional line shows the total occupancy
-- time: displays the time when the file was last modified in each directory
-t: yes-- short for threshold=SIZE, filtering out files and directories smaller than SIZE size
-- exclude=PATTERN: filter file names or directory names that match PATTERN
Use the example
Show all directories and file sizes
The following example shows all directories and the size of the files in the directory. The default unit is Kb.
[root@ecs-centos-7 tt] # du-a temp/4 temp/suba.txt4 temp/test/abc.txt4 temp/test/ha/ha.txt8 temp/test/ha16 temp/test4 temp/time.txt28 temp/
Note: if the-an option is not used in the above example, only the directory size is displayed by default, not the file size. That is, executing du temp/ will only show the directory size. Take a look at the following example:
[root@ecs-centos-7 tt] # du temp8 temp/test/ha16 temp/test28 temp
Display in a readable manner
The default size is only a lonely number, not even a unit, which makes people look a little confused at first glance. The-h option allows the size to be displayed in a human-readable way, which should be the most commonly used.
[root@ecs-centos-7 tt] # du-b temp/4117 temp/test/ha8218 temp/test12326 temp/ [root@ecs-centos-7 tt] # du-h temp/8.0K temp/test/ha16K temp/test28K temp/ [root@ecs-centos-7 tt] # du-- si temp/8.2k temp/test/ha17k temp/test29k temp/
In the above example, the default calculation cardinality of the-h option is 1024 and the default calculation cardinality of the-- si option is 1000
So the size of the temp/test/ha directory with the-h option is 8.0K, while the size calculated with the-- si option is 8.2K
The size units of the-h and-- si options are automatically adjusted according to the size of directories and files
Total directory size
Sometimes we only need to know the total size of a directory. We don't need to know the size of the subdirectory and the files under the subdirectory. We can get the total size of the directory through the-s option.
[root@ecs-centos-7 tt] # du-sh .72K. [root@ecs-centos-7 tt] # du-sh temp/28K temp/
The above example gets the total size of the current directory and the total size of the temp/ directory, respectively
You can also get the total directory size through the-c option, but it shows the subdirectory size first, and the last line shows the total size. In the following example, the 28K before the last line of the total string represents the total size of the temp/ directory.
[root@ecs-centos-7 tt] # du-ch temp/8.0K temp/test/ha16K temp/test28K temp/28K total
Specify directory depth
If a directory has many subdirectories and only wants to display the specified number of layers of directory size, you can use the-d option to implement the
The subdirectory structure of temp/ is as follows:
[root@ecs-centos-7 tt] # tree-d temp/temp/ └── test └── ha2 directories
Specify directory depth
[root@ecs-centos-7 tt] # du-d 0 temp/28 temp/ [root@ecs-centos-7 tt] # du-d 1 temp/16 temp/test28 temp/ [root@ecs-centos-7 tt] # du-- max-depth=2 temp/8 temp/test/ha16 temp/test28 temp/
Du-d 0 temp/: displays the layer 0 directory, that is, the total size of the current directory, which is equivalent to the-s option
Du-d 1 temp/: shows the total size of the layer 1 directory, that is, the temp/test directory
Du-- max-depth=2 temp/: displays the layer 2 directory, that is, the total size of the temp/test/ha directory
Show last modified time
[root@ecs-centos-7 tt] # du-- time temp8 2020-07-21 20:11 temp/test/ha16 2020-07-21 20:11 temp/test28 2020-07-21 20:13 temp
The above example shows the last modification time of each directory, and the granularity of the time is only accurate to minutes.
If you want to show finer granularity, you can use the-- time-syle=STYLE option to specify the output format of the time, where STYLE represents the formatted output string of the date, which is the same format as the formatted output of the date command
Example 1: number of seconds to display UTC time (seconds from January 1, 1970 to the present)
[root@ecs-centos-7 tt] # du-- time--time-style= "+% s" temp/ 8 1595333498 temp/test/ha16 1595333514 temp/test28 1595333582 temp/
Example 2: display the complete year, month, day, hour and second
[root@ecs-centos-7 tt] # du-- time--time-style= "+% F% T" temp/ 8 2020-07-21 20:11:38 temp/test/ha16 2020-07-21 20:11:54 temp/test28 2020-07-21 20:13:02 temp/
Filter by size
Filter out directories and files of the specified size from the displayed results
[root@ecs-centos-7 tt] # du-b temp/4117 temp/test/ha8218 temp/test12326 temp/ [root@ecs-centos-7 tt] # du-b-t 4118 temp/8218 temp/test12326 temp/
In the above example, filter out directories less than 4118 bytes
Filter by directory name or file name
If there are too many subdirectories in a directory, we can filter out the directories and files on the match by matching the subdirectory name or file name with the specified pattern string.
[root@ecs-centos-7 tt] # du-a temp4 temp/suba.txt4 temp/test/abc.txt4 temp/test/ha/ha.txt8 temp/test/ha16 temp/test4 temp/time.txt28 temp [root@ecs-centos-7 tt] # du-a-- exclude=*a* temp/4 temp/test4 temp/time.txt12 temp/
In the above example, the filtered pattern string is: * a *
It means to filter out directories or files with the character an in the directory name or file name. In the example, the first four lines of the directory or file name all contain the a character, so they are all filtered out.
What are the files that fill the disk?
The problem that developers often encounter is that the disk is full, so we can use a combination of du and sort to find out the culprit.
Sort files from large to small in the current directory
[root@ecs-centos-7 tt] # du-sh temp/* | sort-hr10M temp/clpay.tar16K temp/test4.0K temp/time.txt4.0K temp/lnsuba
The current directory and subdirectories are sorted from large to small
[root@ecs-centos-7 tt] # du-ah temp/* | sort-hr10M temp/clpay.tar16K temp/test8.0K temp/test/ha4.0K temp/time.txt4.0K temp/test/ha/ha.txt4.0K temp/test/abc.txt4.0K temp/lnsuba
The three largest directories and subdirectories occupied by disks
[root@ecs-centos-7 tt] # du-ah temp/* | sort-hr | head-n 310m temp/clpay.tar16K temp/test8.0K temp/test/ha on "what is the concept of du in linux" is introduced here, thank you for reading! I believe you all have a certain understanding of "what is the concept of du in linux". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.