Linux disk space size statistics du command common usage

Source: Internet
Author: User

Linux disk space size statistics du command common usage
In Linux, you can collect statistics on the space occupied by a file or folder. Here we will summarize some common usage as follows:

1. Make statistics on the specified file or folder. The default unit is kbyte (k or kilobytes). In the following example, perform statistics on the testa Folder:

[Web @ localhost ~] $ Du-s testa
1589308 testa

2. The correct method for folder statistics. If you want to know the size of the space occupied by a folder, what command should you use? Can I use du directly?
Yes, but it counts all the directories under the folder. Obviously, this is not what we want. The correct method is to use the-s Operator. below is the result of not using-s:
[Web @ localhost Oracle] $ du utils
16 utils/config/10.3
172 utils/config/help/7.2.0.0/en/cw
176 utils/config/help/7.2.0.0/en
204 utils/config/help/7.2.0.0/pt_BR/cw
208 utils/config/help/7.2.0.0/pt_BR
204 utils/config/help/7.2.0.0/fr/cw
208 utils/config/help/7.2.0.0/fr
188 utils/config/help/7.2.0.0/de/cw
192 utils/config/help/7.2.0.0/de
164 utils/config/help/7.2.0.0/zh_CN/cw
168 utils/config/help/7.2.0.0/zh_CN
168 utils/config/help/7.2.0.0/zh_TW/cw
172 utils/config/help/7.2.0.0/zh_TW
176 utils/config/help/7.2.0.0/ko/cw
180 utils/config/help/7.2.0.0/ko
196 utils/config/help/7.2.0.0/es/cw
200 utils/config/help/7.2.0.0/es
192 utils/config/help/7.2.0.0/ja/cw
196 utils/config/help/7.2.0.0/ja
180 utils/config/help/7.2.0.0/it/cw
184 utils/config/help/7.2.0.0/it
1888 utils/config/help/7.2.0.0
1892 utils/config/help
1912 utils/config
8 utils/Cr/config/default
16 utils/Cr/config
3336 utils/Cr/lib
23508 utils/Cr/inventory/pending
23512 utils/Cr/inventory
180 utils/Cr/bin
16 utils/Cr/doc
27188 utils/Cr
20 utils/clone
44 utils/bsu
28 utils/quickstart/images
128 utils/quickstart
572 utils/uninstall/WebLogic_Platform_10.3.6.0
40 utils/uninstall/extftr
712 utils/uninstall
30028 utils

After-s is used:
[Web @ localhost Oracle] $ du-s utils
30028 utils

3. display the actual folder size (calculate the actual file size rather than the disk space occupied)
[Web @ localhost Oracle] $ du -- apparent-size utils
6 utils/config/10.3
103 utils/config/help/7.2.0.0/en/cw
107 utils/config/help/7.2.0.0/en
128 utils/config/help/7.2.0.0/pt_BR/cw
132 utils/config/help/7.2.0.0/pt_BR
128 utils/config/help/7.2.0.0/fr/cw
132 utils/config/help/7.2.0.0/fr
119 utils/config/help/7.2.0.0/de/cw
123 utils/config/help/7.2.0.0/de
94 utils/config/help/7.2.0.0/zh_CN/cw
98 utils/config/help/7.2.0.0/zh_CN
97 utils/config/help/7.2.0.0/zh_TW/cw
101 utils/config/help/7.2.0.0/zh_TW
111 utils/config/help/7.2.0.0/ko/cw
115 utils/config/help/7.2.0.0/ko
119 utils/config/help/7.2.0.0/es/cw
123 utils/config/help/7.2.0.0/es
124 utils/config/help/7.2.0.0/ja/cw
128 utils/config/help/7.2.0.0/ja
114 utils/config/help/7.2.0.0/it/cw
118 utils/config/help/7.2.0.0/it
1175 utils/config/help/7.2.0.0
1179 utils/config/help
1188 utils/config
5 utils/Cr/config/default
9 utils/Cr/config
3284 utils/Cr/lib
23456 utils/Cr/inventory/pending
23460 utils/Cr/inventory
153 utils/Cr/bin
16 utils/Cr/doc
27036 utils/Cr
7 utils/clone
30 utils/bsu
15 utils/quickstart/images
102 utils/quickstart
546 utils/uninstall/WebLogic_Platform_10.3.6.0
40 utils/uninstall/extftr
672 utils/uninstall
29055 utils
The actual size of the file is always smaller than the occupied space.

4. What should I do if I want to make the results seem easy to read? That is, the space size that we usually use in the mouth, that is, the size of the space to be converted to G, M, or K, is of course just an estimate.
[Web @ localhost ~] $ Du-s-h testa
1.6G testa

5. Specify the statistical unit. The statistical unit can be blocks (512 bytes), bytes, and Kbyte (bytes ).
Block-based statistics:
[Web @ localhost ~] $ Du-s-B 512 testa
3178616 testa

Statistics by byte
[Web @ localhost ~] $ Du-s-B 1 testa
1627451392 testa

Statistics by K bytes
[Web @ localhost ~] $ Du-s-B 1024 testa
1589308 testa

6. Statistics depth. For example, I not only want to view the size of each folder in the current directory, but also want to see the size of each folder in the second directory.
[Web @ localhost Oracle] $ du -- max-depth = 2
1912./utils/config
27188./utils/Cr
20./utils/clone
44./utils/bsu
128./utils/quickstart
712./utils/uninstall
30028./utils
21240./wlserver_10.3/common
4./wlserver_10.3/L10N
16./wlserver_10.3/inventory
454968./wlserver_10.3/server
3460./wlserver_10.3/sip
196./wlserver_10.3/uninstall
479896./wlserver_10.3
11936./coherence_3.7/lib
12./coherence_3.7/inventory
52./coherence_3.7/bin
8./coherence_3.7/uninstall
12024./coherence_3.7
228./modules/junit_1.0.0.0_4-5
216./modules/net. sf. antcontrib_1.1.0.0_1-0b2
688./modules/features
1852./modules/com. bea. weblogic. jms. dotnetclient_1.3.2.0
4164./modules/org. apache. ant_1.7.1
143464./modules
185472./user_projects/domains
185476./user_projects
24./logs
851044.

That is to say, the two levels of directories are separately counted, where the sub-folders are counted (the sum of the space occupied by the folder content), which is the same as the separate statistics folder, such
./Wlserver_10.3/common: 21240. separate statistics on this folder. Try again:
[Web @ localhost Oracle] $ du-s./wlserver_10.3/common
21240./wlserver_10.3/common

7. Are too many output rows? No line breaks!
[Web @ localhost Oracle] $ du-0 utils
16 utils/config/10.3172 utils/config/help/7.2.0.0/en/cw176 utils/config/help/7.2.0.0/en204 utils/config/help/7.2.0.0/pt_BR/cw208 utils/config /help/7.2.0.0/pt_BR204 utils/config/help/7.2.0.0/fr/cw208 utils/config/help/7.2.0.0/fr188 utils/config/help/7.2.0.0/de/cw192 utils/config /help/7.2.0.0/de164 utils/config/help/7.2.0.0/zh_CN/cw168 utils/config/help/7.2.0.0/zh_CN168 utils/config/help/7.2.0.0/zh_TW/cw172 utils/config /help/7.2.0.0/zh_TW176 utils/config/help/7.2.0.0/ko/cw180 utils/config/help/7.2.0.0/ko196 utils/config/help/7.2.0.0/es/cw200 utils/config /help/7.2.0.0/es192 utils/config/help/7.2.0.0/ja/cw196 utils/config/help/7.2.0.0/ja180 utils/config/help/7.2.0.0/it/cw184 utils/config /help/7.2.0.0/it1888 utils/config/help/7.2.0.01892 utils/config/help1912 utils/config8 utils/ccr/config/default16 utils/ccr/config3336 utils/ccr/lib23508 utils/ ccr/inventory/pending23512 utils/ccr/inventory180 utils/ccr/bin16 utils/ccr/doc27188 utils/ccr20 utils/clone44 utils/logs/quickstart/images128 utils/quickstart572 utils/uninstall/ webLogic_Platform_10.3.6.040 util

8. If you do not want to include some files in statistics, use -- exclude = [pattern] to remove them. In the following example, perform statistics on logs in the folder:
[Web @ localhost logs] $ ls-l
Total 20
-Rw-r -- 1 web weblogic 1317 07-02 log.txt
-Rw-r ----- 1 web weblogic 1743 07-02 wlsconfig_20140702092113.log
-Rw-r ----- 1 web weblogic 1743 07-02 wlsconfig_20140702092546.log
-Rw-r ----- 1 web weblogic 1743 07-02 wlsconfig_20140702092738.log
-Rw-r ----- 1 web weblogic 1743 07-02 wlsconfig_20140702092819.log

There can be a total of five files in the folder, each of which is about 2 k in size. Check the actual space occupied.
[Web @ localhost logs] $ du-s *
4 log.txt
4 wlsconfig_20140702092113.log
4 wlsconfig_20140702092546.log
4 wlsconfig_20140702092738.log
4 wlsconfig_20140702092819.log
The actual space occupied by each node is about 4 K (Note: There is a difference between the space occupied by the file and the file size)
[Web @ localhost logs] $ du -- apparent-size *
2 log.txt
2 wlsconfig_20140702092113.log
2 wlsconfig_20140702092546.log
2 wlsconfig_20140702092738.log
2 wlsconfig_20140702092819.log
About 2 k bytes

[Web @ localhost logs] $ du -- apparent-size-B 1 *
1317 log.txt
1743 wlsconfig_20140702092113.log
1743 wlsconfig_20140702092546.log
1743 wlsconfig_20140702092738.log
1743 wlsconfig_20140702092819.log
When byte statistics are used, the results are the same as those obtained by the ls command.

[Web @ localhost logs] $ cd ..
[Web @ localhost Oracle] $ du-s logs
24 logs

Statistics after txt files are not included, 4 k smaller
[Web @ localhost Oracle] $ du-s -- exclude = *. txt logs
20 logs

9. Statistics on symbolic links. When calculating the disk space of a folder for an hour, the actual storage location of symbolic links may be in other partitions. Statistics are not collected by default, use the-L parameter.
[Web @ localhost logs] $ ls-l ../registry. xml
-Rw-r -- 1 web weblogic 1908 07-02 ../registry. xml

The actual size of registry. xml is about 2 K, and two symbolic links are created:
[Web @ localhost logs] $ ln-s ../registry. xml./test. xml
[Web @ localhost logs] $ ln-s ../registry. xml test2.xml

[Web @ localhost logs] $ ls-l
Total 20
-Rw-r -- 1 web weblogic 1317 07-02 log.txt
Lrwxrwxrwx 1 web weblogic 15 07-11 10:36 test2.xml-> ../registry. xml
Lrwxrwxrwx 1 web weblogic 15 07-11 test. xml-> ../registry. xml
-Rw-r ----- 1 web weblogic 1743 07-02 wlsconfig_20140702092113.log
-Rw-r ----- 1 web weblogic 1743 07-02 wlsconfig_20140702092546.log
-Rw-r ----- 1 web weblogic 1743 07-02 wlsconfig_20140702092738.log
-Rw-r ----- 1 web weblogic 1743 07-02 wlsconfig_20140702092819.log


At this time, we can see that the calculated disk space is 8 k more and is changed to 32
[Web @ localhost Oracle] $ du-L logs
32 logs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.