linux du

来源:互联网 发布:sqlserver是免费的吗 编辑:程序博客网 时间:2024/04/27 17:03

du帮助文档 1

NAME 1

Linux系统的文件右键属性中查看文件夹大小 4

 

du帮助文档

NAME

du - estimate file space usage(评估文件的使用情况)
SYNOPSIS
       du [OPTION]... [FILE]...
       du [OPTION]... --files0-from=F
DESCRIPTION
       Summarize disk usage of each FILE, recursively for directories.
       Mandatory  arguments  to  long  options are mandatory for short options too.(选项必须用的参数在使用短选项时也是必须的。)
       -a, --all
              write counts for all files, not just directories

[maijunjin@localhost test]$ du -a

10240   ./inner3/output.dat

10244   ./inner3

10240   ./inner/innerinner/output.dat

10244   ./inner/innerinner

10240   ./inner/output.dat

20488   ./inner

12      ./du.txt

10240   ./inner2/output.dat

10244   ./inner2

40992   .

[maijunjin@localhost test]$ du

10244   ./inner3

10244   ./inner/innerinner

20488   ./inner

10244   ./inner2

40992   .


       --apparent-size
              print apparent sizes,  rather  than  disk  usage;  although  the               apparent  size is usually smaller, it may be larger due to holes in (sparse) files, internal  fragmentation,  indirect  blocks,and the like

       -B, --block-size=SIZE
              use SIZE-byte blocks

du

效果等同于

du  --block-size=1024



       -b, --bytes
              equivalent to --apparent-size --block-size=1

       -c, --total
              produce a grand total
没有什么作用,就是显示的时候增加了:

大小       total


       -D, --dereference-args
              dereference only symlinks that are listed on the command line

Dereference symbolic links that are command line arguments. Does not affect other symbolic links. This is helpful for finding out the disk usage of directories, such as /usr/tmp, which are often symbolic links. 

[maijunjin@localhost test]$ ls -la

total 244

drwxrwxr-x. 2 maijunjin maijunjin   4096 Jun  7 13:55 .

drwxr-xr-x. 3 maijunjin maijunjin   4096 Jun  7 04:04 ..

-rw-r--r--. 1 maijunjin maijunjin  16384 Jun  7 04:11 .du.txt.swp

lrwxrwxrwx. 1 maijunjin maijunjin     26 Jun  7 13:55 output.dat -> /home/maijun                                                                                                                     jin/output.dat

-rwxr-xr-x. 1 maijunjin maijunjin 213616 Jun  7 06:13 sendmail

-rw-rw-r--. 1 maijunjin maijunjin     74 Jun  7 06:12 space_report

-rw-rw-r--. 2 maijunjin maijunjin     74 Jun  7 06:05 space_report2

lrwxrwxrwx. 1 maijunjin maijunjin     40 Jun  7 06:30 space_report3A -> /home/ma                                                                                                                     ijunjin/Desktop/space_report.txt

lrwxrwxrwx. 1 maijunjin maijunjin     29 Jun  7 06:27 test -> /home/maijunjin/De                                                                                                                     sktop/test/

[maijunjin@localhost test]$ du -D

240     .//对整个目录是没有效果的

[maijunjin@localhost test]$ du

240     .//不计算软连接当前目录的大小

[maijunjin@localhost test]$ du -L

4       ./test

10484   .//统计了软链接当前目录的大小

[maijunjin@localhost test]$ du -D output.dat

10240   output.dat//只能在命令行中指定软链接

[maijunjin@localhost test]$ du output.dat

0       output.dat



       --files0-from=F
              summarize  disk usage of the NUL-terminated file names specified
              in file F; If F is - then read names from standard input

[maijunjin@localhost test]$ du --files0-from=-

Output.dat//输入文件名之后立即按crtl+D两次

结果:

[maijunjin@localhost test]$ du --files0-from=-

output.dat0     output.dat

 

 


       -H     equivalent to --dereference-args (-D)

       -h, --human-readable
              print sizes in human readable format (e.g., 1K 234M 2G)

       --si   like -h, but use powers of 1000 not 1024

       -k     like --block-size=1K

       -l, --count-links
              count sizes many times if hard linked

如果想要明白这个选项的用途,可以查阅:http://stackoverflow.com/questions/19951883/du-counting-hardlinks-towards-filesize

 

[maijunjin@localhost test]$ du

10244   ./test2

4       ./test

10252   .

[maijunjin@localhost test]$ du -l

10244   ./test2//test2中有对output.dat文件的硬链接

10244   ./test//同样test目录中也有多output.dat文件的硬链接

20492   .

如果不加上-l,那么多个相同文件的硬链接只会统计一次,加上-l会统计一次

 


       -m     like --block-size=1M

       -L, --dereference
              dereference all symbolic links

       -P, --no-dereference
              don’t follow any symbolic links (this is the default)

       -0, --null
              end each output line with 0 byte rather than newline
显示结果的时候有区别

[maijunjin@localhost test]$ du -0

4       ./innertest24   ./innertest10252        .[maijunjin@localhost test]$


       -S, --separate-dirs
              do not include size of subdirectories

[maijunjin@localhost test]$ du

4       ./innertest2

4       ./innertest

10252   .

[maijunjin@localhost test]$ du -S

4       ./innertest2

4       ./innertest

10244   .


       -s, --summarize
              display only a total for each argument

[maijunjin@localhost test]$ du

4       ./innertest2

4       ./innertest

10252   .

[maijunjin@localhost test]$ du -s

10252   .


       -x, --one-file-system
              skip directories on different file systems

       -X, --exclude-from=FILE
              exclude files that match any pattern in FILE

[maijunjin@localhost test]$ du -X filter

4       ./innertest2

10252   .

[maijunjin@localhost test]$ cat filter

innertest

[maijunjin@localhost test]$ du

4       ./innertest2

4       ./innertest

10256   .


       --exclude=PATTERN
              exclude files that match PATTERN

[maijunjin@localhost test]$ du --exclude=inner*

10248   .

[maijunjin@localhost test]$ du --exclude=innertest

4       ./innertest2

10252   .


       --max-depth=N
              print the total for a directory (or file, with --all) only if it
              is   N   or  fewer  levels  below  the  command  line  argument;
              --max-depth=0 is the same as --summarize

[maijunjin@localhost test]$ du --max-depth=0

40980   .

[maijunjin@localhost test]$ du --max-depth=1

10244   ./inner3

20488   ./inner

10244   ./inner2

40980   .

[maijunjin@localhost test]$ du --max-depth=2

10244   ./inner3

10244   ./inner/innerinner

20488   ./inner

10244   ./inner2

40980   .


       --time show time of the last modification of any file in the directory,or any of its subdirectories

[maijunjin@localhost test]$ du --time

10244   2014-06-07 15:45        ./inner3

10244   2014-06-07 15:46        ./inner/innerinner

20488   2014-06-07 15:46        ./inner

10244   2014-06-07 15:45        ./inner2

40980   2014-06-07 15:46        .

[maijunjin@localhost test]$ du

10244   ./inner3

10244   ./inner/innerinner

20488   ./inner

10244   ./inner2

40980   .


       --time=WORD
              show  time  as WORD instead of modification time: atime, access,
              use, ctime or status

[maijunjin@localhost test]$ du --time=atime

10244   2014-06-07 15:46        ./inner3

10244   2014-06-07 15:46        ./inner/innerinner

20488   2014-06-07 16:19        ./inner

10244   2014-06-07 15:46        ./inner2

40980   2014-06-07 16:19        .

[maijunjin@localhost test]$ du --time=access

10244   2014-06-07 15:46        ./inner3

10244   2014-06-07 15:46        ./inner/innerinner

20488   2014-06-07 16:19        ./inner

10244   2014-06-07 15:46        ./inner2

40980   2014-06-07 16:19        .

[maijunjin@localhost test]$ du --time=use

10244   2014-06-07 15:46        ./inner3

10244   2014-06-07 15:46        ./inner/innerinner

20488   2014-06-07 16:19        ./inner

10244   2014-06-07 15:46        ./inner2

40980   2014-06-07 16:19        .

[maijunjin@localhost test]$ du --time=ctime

10244   2014-06-07 15:45        ./inner3

10244   2014-06-07 15:46        ./inner/innerinner

20488   2014-06-07 16:19        ./inner

10244   2014-06-07 15:45        ./inner2

40980   2014-06-07 16:19        .

[maijunjin@localhost test]$ du --time=status

10244   2014-06-07 15:45        ./inner3

10244   2014-06-07 15:46        ./inner/innerinner

20488   2014-06-07 16:19        ./inner

10244   2014-06-07 15:45        ./inner2

40980   2014-06-07 16:19        .

[maijunjin@localhost test]$


       --time-style=STYLE
              show times using style STYLE: full-iso, long-iso,  iso,  +FORMAT
              FORMAT is interpreted like date

[maijunjin@localhost test]$ du --time --time-style=full-iso

10244   2014-06-07 15:45:58.642005219 -0700     ./inner3

10244   2014-06-07 15:46:43.513005191 -0700     ./inner/innerinner

20488   2014-06-07 16:19:24.728003979 -0700     ./inner

10244   2014-06-07 15:45:51.329005223 -0700     ./inner2

40980   2014-06-07 16:19:24.728003979 -0700     .

[maijunjin@localhost test]$ du --time --time-style=long-iso

10244   2014-06-07 15:45        ./inner3

10244   2014-06-07 15:46        ./inner/innerinner

20488   2014-06-07 16:19        ./inner

10244   2014-06-07 15:45        ./inner2

40980   2014-06-07 16:19        .

[maijunjin@localhost test]$ du --time --time-style=iso

10244   2014-06-07      ./inner3

10244   2014-06-07      ./inner/innerinner

20488   2014-06-07      ./inner

10244   2014-06-07      ./inner2

40980   2014-06-07      .

 

[maijunjin@localhost test]$ du --time --time-style='+%Y-%m-%d %H:%M'

10244   2014-06-07 15:45        ./inner3

10244   2014-06-07 15:46        ./inner/innerinner

20488   2014-06-07 16:19        ./inner

10244   2014-06-07 15:45        ./inner2

40980   2014-06-07 16:19        .


       --help display this help and exit

       --version
              output version information and exit

[maijunjin@localhost test]$ du --version

du (GNU coreutils) 8.4

Copyright (C) 2010 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.

 

Written by Torbjörn Granlund, David MacKenzie, Paul Eggert,

and Jim Meyering.


       Display   values  are  in  units  of  the  first  available  SIZE  from
       --block-size, and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE  environ-
       ment  variables.   Otherwise,  units  default  to 1024 bytes (or 512 if
       POSIXLY_CORRECT is set).

       SIZE may be (or may be an integer optionally followed by) one  of  fol-
       lowing: KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T,
       P, E, Z, Y.

PATTERNS
       PATTERN is a shell pattern (not a regular expression).  The  pattern  ?
       matches  any  one  character, whereas * matches any string (composed of
       zero, one or multiple characters).  For example,  *.o  will  match  any
       files whose names end in .o.  Therefore, the command

              du --exclude='*.o'

       will skip all files and subdirectories ending in .o (including the file
       .o itself).



Linux系统的文件右键属性中查看文件夹大小

下图是右键之后查看到的大小:

 

但是在命令行上:

[maijunjin@localhost Documents]$ du

20      ./test

24      .

为什么:

[maijunjin@localhost Documents]$ du -S

20      ./test  //有个test目录,大小是20k,所以总大小加上本目录的大小是24k

4       .

[maijunjin@localhost Documents]$ ls

test

 

 

du选项的分类

显示

-a, --all write counts for all files, not just directories

-c, --total produce a grand total
-0, --null end each output line with 0 byte rather than newline
 -s, --summarize  display only a total for each argument
--max-depth=N   print the total for a directory (or file, with --all) only if it is   N   or  fewer  levels  below  the  command  line  argument;--max-depth=0 is the same as --summarize
 --time show time of the last modification of any file in the directory,or any of its subdirectories
--time=WORD show  time  as WORD instead of modification time: atime, access,
              use, ctime or status
--time-style=STYLE  show times using style STYLE: full-iso, long-iso,  iso,  +FORMAT
              FORMAT is interpreted like date

 

单位的设置

-B, --block-size=SIZE use SIZE-byte blocks

-b, --bytes equivalent to --apparent-size --block-size=1
 -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
--si   like -h, but use powers of 1000 not 1024
-k     like --block-size=1K
-m     like --block-size=1M

内容的设置

--apparent-size print apparent sizes,  rather  than disk usage; although the apparent  size is usually smaller, it may be larger due to holes in (sparse) files, internal  fragmentation,  indirect  blocks,and the like

 -D, --dereference-args dereference only symlinks that are listed on the command line

-H     equivalent to --dereference-args (-D)
 -l, --count-links count sizes many times if hard linked
-L, --dereference dereference all symbolic links

需要区别-D-L-D后面必须加上软链接的文件名,而-L是当前目录下面的所有软链接都会统计该软链接链接到的文件的大小
-P, --no-dereference don’t follow any symbolic links (this is the default)
 -S, --separate-dirs  do not include size of subdirectories
-X, --exclude-from=FILE     exclude files that match any pattern in FILE

--exclude=PATTERN  exclude files that match PATTERN

输入源的设置

--files0-from=F summarize  disk usage of the NUL-terminated file names specified
              in file F; If F is - then read names from standard input


0 0
原创粉丝点击