N-day learning of a Linux command du

Source: Internet
Author: User
Tags readable

Use

Statistics file or directory occupies hard disk space size

Usage

du [OPTION] [FILE]
Du [OPTION]--files0-from=f

Common parameters

-A,--all
Count all files, not just directories

-B,--bytes
Bytes in units of statistics

-C,--total
Total output size

-D,--dereference-args
To the command line out of the link file, according to the link file point to the actual file size statistics, the default is the size of the linked file

--files0-from=f
Reads the list of files that need to be counted from the specified file F, with multiple filenames separated by a null character (nul-terminated file names). If "-", this means reading from the standard input stream.

-H,--human-readable
Human readable way to display

--si
As with the-h option, multiples are 1000 not 1024

-K
In units of K

-L,--count-links
Repeating hard Links

-M
In units of M

-L,--dereference
All linked files are counted in real file size

-P,--no-dereference
Link file statistics itself size, default

-0,--null
Output no newline display, NULL byte connection

-S,--separate-dirs
No subdirectories are included when statistics are available

-S,--summarize
Show total statistics for files

-X,--one-file-system
Ignore directories for different file systems

-X,--exclude-from=file
Read the list of files to be excluded from the file, the file name can contain the shell wildcard character

--exclude=pattern
Files that match the matching pattern are not counted

--max-depth=n
Statistics directory depth, n=0 similar to-s option, n=1 statistics to the first level subdirectory, and so on

--help
Output Help information

--version
Output version Information


Practice

1. Statistics of all files occupied space information (human readable mode display)

1[Email protected] assets]#du-Ah219M./game/game_asia_5_release_1.3.5_15.Zip320M./game/game_asia_5_release_1.4.0_21.Zip420M./game/game_asia_7_debug_1.4.0_20.Zip559M./Game6332K./hotgame/hotgame_asia_5_release_1.3.5.15_1.4.0. +.Zip7332K./Hotgame834M./source/asia/com.pokergame.dominoqq_release_1.3. 5_20171223183437.apk936M./source/asia/com.pokergame.dominoqq_release_1.4. 0_20180113181031.apkTen40M./source/asia/com.pokergame.susun_debug_1.4. 0_20180110113325.apk One109M./source/Asia A 0./source/Thailand -109M./Source -167M.
View Code


2. Statistics empty character delimited list of files, link file shows true size in bytes
Generate a space-delimited list of files

1 Echo ' ntp.conf\0pip-9.0.1.tar.gz ' > t.log2 in/var/spool/mail/root3 [[Email protected] ~ ]# ll41 root root       : T.log
View Code

Statistics file space consumption

1 du -b-d--files0-from=t.log21830    ntp.conf31197370 pip-9.0. 1. tar. gz
View Code


3. No Line break display

1[Email protected] assets]#du-ah-0219M./game/game_asia_5_release_1.3.5_15.zip20m./game/game_asia_5_release_1.4.0_21.zip20m./game/game_asia_7_debug_1.4.0_20.zip59m./game332k./hotgame/hotgame_asia_5_release_1.3.5.15_1.4.0. +. zip332k./hotgame34m./source/asia/com.pokergame.dominoqq_release_1.3.5_20171223183437.apk36m./source/asia/com.pokergame.dominoqq_release_1.4.0_20180113181031.apk40m./source/asia/com.pokergame.susun_debug_1.4.0_20180110113325.apk109m./source/asia0./source/thailand109m./source167m.
View Code


4. Statistics do not contain subdirectories

1[Email protected] assets]#du-ah-S219M./game/game_asia_5_release_1.3.5_15.Zip320M./game/game_asia_5_release_1.4.0_21.Zip420M./game/game_asia_7_debug_1.4.0_20.Zip559M./Game6332K./hotgame/hotgame_asia_5_release_1.3.5.15_1.4.0. +.Zip7332K./Hotgame834M./source/asia/com.pokergame.dominoqq_release_1.3. 5_20171223183437.apk936M./source/asia/com.pokergame.dominoqq_release_1.4. 0_20180113181031.apkTen40M./source/asia/com.pokergame.susun_debug_1.4. 0_20180110113325.apk One109M./source/Asia A 0./source/Thailand - 4.0K./Source - 0.
View Code


5. Display the total statistics of the catalog

1 [[email protected] assets]# du -H-s 2 167M.


6. Do not count files that contain the game keyword

1 [email protected] assets]# ll2Total83DRWXRWX---.1Root vboxsf4096Jan -  One: theGame4DRWXRWX---.1Root vboxsf0Jan -  One: -Hotgame5DRWXRWX---.1Root vboxsf4096Jan -  One: GenevaSource6You have mailinch/var/spool/mail/Root7[Email protected] assets]#du-S--exclude='Game'8 111196  .9[Email protected] assets]#du-sTen 170708  . One[Email protected] assets]#du-S--exclude='Game' A 111196.


7. Statistic subdirectory space and sort in descending order

1 du -h-b--max-depth=1sort -2174782502   . 3 113516252   . /Source460929746    ./Game5336504  ./ Hotgame

Resources

"1" Linux Shell wildcard characters, metacharacters, escape character usage examples introduced
Http://www.cnblogs.com/chengmo/archive/2010/10/17/1853344.html
"2" Man du
"3" a Linux command per day: du command
Http://www.cnblogs.com/peida/archive/2012/12/10/2810755.html
"4" representing/quoting NUL on the command line
Https://unix.stackexchange.com/questions/160598/representing-quoting-nul-on-the-command-line

N-day learning of a Linux command du

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.