Linux disk space Size statistics du command common usage

Source: Internet
Author: User

Under Linux, you can count the amount of space a file or folder occupies, and here are some common usage summaries:

1, the specified file or folder statistics, the default unit is KByte (k or kilobytes), the following example of the folder Testa statistics:

[email protected] ~]$ du-s Testa
1589308 Testa

2, the correct method of folder statistics, if you want to know the size of the space occupied by a folder, what command? Can I use du directly?
Can be yes, but it will count all the directories under that folder again, obviously this is not what we want. The correct approach is to use the-S operator, the following is the result without-s:
[email protected] oracle]$ du Utils
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
Utils/config/help/7.2.0.0/ko
196 UTILS/CONFIG/HELP/7.2.0.0/ES/CW
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
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/ccr/config/default
Utils/ccr/config
3336 Utils/ccr/lib
23508 utils/ccr/inventory/pending
23512 utils/ccr/inventory
Utils/ccr/bin
Utils/ccr/doc
27188 UTILS/CCR
Utils/clone
Utils/bsu
Utils/quickstart/images
Utils/quickstart
572 utils/uninstall/weblogic_platform_10.3.6.0
Utils/uninstall/extftr
712 Utils/uninstall
30028 Utils

After using-s:
[Email protected] oracle]$ du-s utils
30028 Utils

3, display the actual folder size (the actual file size statistics, not to the occupied disk space statistics)
[email protected] 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
Utils/config/help/7.2.0.0/pt_br/cw
Utils/config/help/7.2.0.0/pt_br
Utils/config/help/7.2.0.0/fr/cw
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
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
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
Utils/config/help/7.2.0.0/ja
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/ccr/config/default
9 Utils/ccr/config
3284 Utils/ccr/lib
23456 utils/ccr/inventory/pending
23460 utils/ccr/inventory
153 Utils/ccr/bin
Utils/ccr/doc
27036 UTILS/CCR
7 Utils/clone
Utils/bsu
Utils/quickstart/images
102 Utils/quickstart
546 utils/uninstall/weblogic_platform_10.3.6.0
Utils/uninstall/extftr
672 Utils/uninstall
29055 Utils
You can see that the actual size of the file is always smaller than the space occupied.

4. What if you want to make the results seem easy to read? That is, the size of the space we are accustomed to talking about, that is, how much g, or how many m, or how many k, of course, is only an estimate.
[email protected] ~]$ du-s-H Testa
1.6G Testa

5, the designated statistical units, statistical units can be blocks (512byte), Byte,kbyte (Kbytes)such as
Statistics by BLOCK:
[email protected] ~]$ Du-s-B Testa
3178616 Testa

Statistics by byte
[[email protected] ~]$ Du-s-B 1 Testa
1627451392 Testa

Statistics by K bytes
[email protected] ~]$ Du-s-B 1024x768 Testa
1589308 Testa

6, the depth of statistics, for example, I want to see not only the size of the folder in the current directory, I also want to see the level two directory under the size of each folder
[email protected] oracle]$ du--max-depth=2
1912./utils/config
27188./UTILS/CCR
/utils/clone.
/utils/bsu.
/utils/quickstart.
712./utils/uninstall
30028./utils
21240./wlserver_10.3/common
4./wlserver_10.3/l10n
/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
/coherence_3.7/inventory.
/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
/logs.
851044.

In other words, the level two directory is counted separately, where the sub-folder statistics (the contents of the folder and the amount of space), which is the same as the individual statistics folder, such as the
The result of the./wlserver_10.3/common statistic is 21240, and the folder is counted separately:
[email protected] oracle]$ du-s./wlserver_10.3/common
21240./wlserver_10.3/common

7, too many output rows too? That's not going to change!
[Email protected] 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/bsu28utils/quickstart/images128    utils/quickstart572     utils/uninstall/WebLogic_Platform_10.3.6.040    util

8, statistics, do not want to be some of the file statistics, how to do, use--exclude=[pattern] removed, the following example, the folder logs statistics:
[email protected] logs]$ ls-l
Total 20
-rw-r--r--1 Web WebLogic 1317 07-02 09:19 Log.txt
-rw-r-----1 Web weblogic 1743 07-02 09:25 Wlsconfig_20140702092113.log
-rw-r-----1 Web weblogic 1743 07-02 09:27 Wlsconfig_20140702092546.log
-rw-r-----1 Web weblogic 1743 07-02 09:28 Wlsconfig_20140702092738.log
-rw-r-----1 Web weblogic 1743 07-02 09:29 wlsconfig_20140702092819.log

Can have a total of 5 files in the folder, each file size of about 2K, look at the actual size of occupied space
[Email protected] 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 4k or so (note: File space and file size are different)
[email protected] logs]$ du--apparent-size *
2 Log.txt
2 Wlsconfig_20140702092113.log
2 Wlsconfig_20140702092546.log
2 Wlsconfig_20140702092738.log
2 Wlsconfig_20140702092819.log
Use K-byte statistics around 2K

[email protected] 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
Using byte statistics, the same as the file size obtained by the LS command

[email protected] logs]$ CD.
[Email protected] oracle]$ du-s logs
Logs

Not include TXT file after statistics, size less 4k
[email protected] oracle]$ du-s--exclude=*.txt logs
Logs

9, statistical symbolic link, in the statistics of a folder disk space size, the actual location of the symbolic link can be stored on other partitions, the default is not statistical, to be counted, use the-l parameter
[email protected] logs]$ ls-l. /registry.xml
-rw-r--r--1 Web weblogic 1908 07-02 09:19.. /registry.xml

You can see the registry.xml actual size around 2K, creating two symbolic Links:
[Email protected] logs]$ ln-s. /registry.xml./test.xml
[Email protected] logs]$ ln-s. /registry.xml Test2.xml

[Email protected] logs]$ ls-l
Total 20
-rw-r--r--1 Web WebLogic 1317 07-02 09:19 Log.txt
lrwxrwxrwx 1 Web WebLogic 07-11 10:36 test2.xml. /registry.xml
lrwxrwxrwx 1 Web WebLogic 07-11 10:36 test.xml. /registry.xml
-rw-r-----1 Web weblogic 1743 07-02 09:25 Wlsconfig_20140702092113.log
-rw-r-----1 Web weblogic 1743 07-02 09:27 Wlsconfig_20140702092546.log
-rw-r-----1 Web weblogic 1743 07-02 09:28 Wlsconfig_20140702092738.log
-rw-r-----1 Web weblogic 1743 07-02 09:29 wlsconfig_20140702092819.log


At this point, you can see the statistics of disk space is 8k, became 32
[Email protected] oracle]$ du-l logs
Logs

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.