日期:2014-05-16  浏览次数:20810 次

Linux下磁盘管理命令df与du
对磁盘进行查看和控制的两个linux命令,df和du。

一、du命令
首先看一下du的help说明:
[root@misdwh opt]# du --help
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
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
      --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
  -b, --bytes           equivalent to `--apparent-size --block-size=1'
  -c, --total           produce a grand total
  -D, --dereference-args  dereference FILEs that are symbolic links
      --files0-from=F   summarize disk usage of the NUL-terminated file
                          names specified in file F
  -H                    like --si, but also evokes a warning; will soon
                          change to be 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
  -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
  -S, --separate-dirs   do not include size of subdirectories
  -s, --summarize       display only a total for each argument
  -x, --one-file-system  skip directories on different file systems
  -X FILE, --exclude-from=FILE  Exclude files that match any pattern in FILE.
      --exclude=PATTERN Exclude files that match PATTERN.
      --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'
      --help     display this help and exit
      --version  output version information and exit
 
SIZE may be (or may be an integer optionally followed by) one of following:
kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

语法:du [ -a | -s ] [ -k ] [ -m ] [ -g ][ -l ] [ -r ] [ -x ] [ -H | -L ][ File ... ]

描述:du命令显示用于文件的块数量。如果指定的File参数实际上是一个目录,就要报告该目录内的所有文件。如果没有提供File参数,du命令使用当前目录内的文件。 如果File参数是一个目录,那么报告的块的数量就是分配到目录中文件以及分配到目录自身的块之和。

指定-a标志:报告个体文件中块数量。不管是否使用了-a标志,由File参数指定的个体文件总是要列出。
指定-s标志:报告用于所有指定文件和目录中所有文件的全部块。

分类解说一下各个参数的含义:
-a 显示文件夹中的所有文件夹、文件的大小。默认只显示文件夹大小,不显示文件。
-B 以xxByte为单位显示块数(默认为1024)
-b 以1Byte为单位显示块数(但貌似与-B1的结果不同)
-c 最后显示一行汇总数据
-h 以方便阅读的方式展现大小(是以1000为单位,而非1024)
-k 用 1024 字节单位计算块数,而不是用缺省的 512 字节单位。
-m 用 MB 单位计算块数,而不是用缺省的 512 字节单位。
-0 注意是数字“0”,而非字母“O”。表示每行后面不换行,直接跟下去
-S 外层的文件夹大小不包含内层大小
-s 只显示整个对象文件夹的合计大小。将该标志与-a标志进行对比。
-x 在评估文件大小时,只评估那些与File参数指定的文件或者目录驻留在相同设备上的文件。

注:
1、具有多个链接的文件只为一个条目计数和书写。
2、由于块计数只基于文件大小,所以在报告的块数中,未分配的块是没有包含进去的。
3、如果du得不到文件属性,或者无法读取目录,它就报告一个错误,并且会影响命令的退出状态。
4、如果同时指定-k、-m标志,则后面的那个起作用。且输出结果四舍五入。