Linux命令之du

File: coreutils.info,  Node: du invocation,  Next: stat invocation,  Prev: df invocation,  Up: Disk usage

14.2 'du': Estimate file space usage
====================================

'du' reports the amount of disk space used by the specified files and
for each subdirectory (of directory arguments).  Synopsis:
"du"报告指定文件和每个子目录使用的磁盘空间量(目录参数)。简介:

     du [OPTION]... [FILE]...

   With no arguments, 'du' reports the disk space for the current
directory.  Normally the disk space is printed in units of 1024 bytes,
but this can be overridden (*note Block size::).  Non-integer quantities
are rounded up to the next higher unit.
   如果没有参数, "du"将报告当前目录的磁盘空间。磁盘空间通常以1024 bytes为单位打印, 
但这可以被覆盖(*note Block size::)。非整数的数量四舍五入到下一个更高的单位。

   If two or more hard links point to the same file, only one of the
hard links is counted.  The FILE argument order affects which links are
counted, and changing the argument order may change the numbers that
'du' outputs.
   如果两个或多个硬链接指向同一个文件, 则只有一个硬链接参与计数。FILE参数的顺序影响
哪些链接计数, 如果改变FILE参数的顺序可能会影响"du"的输出结果。

   The program accepts the following options.  Also see *note Common
options::.
   该程序接受以下操作(选项)。也可参见"*note"中的常见操作(选项)。

'-0'
'--null'
     Output a zero byte (ASCII NUL) at the end of each line, rather than
     a newline.  This option enables other programs to parse the output
     of 'du' even when that output would contain data with embedded
     newlines.
     在每行末尾输出一个零字节(ASCII NUL), 而不是一个换行符。此选项允许其它程序解析输出, 
     即使输出中包含了嵌入的换行符。

'-a'
'--all'
     Show counts for all files, not just directories.
     显示所有文件的计数, 不仅仅是目录。

'--apparent-size'
     Print apparent sizes, rather than disk usage.  The apparent size of
     a file is the number of bytes reported by 'wc -c' on regular files,
     or more generally, 'ls -l --block-size=1' or 'stat --format=%s'.
     For example, a file containing the word 'zoo' with no newline
     would, of course, have an apparent size of 3.  Such a small file
     may require anywhere from 0 to 16 KiB or more of disk space,
     depending on the type and configuration of the file system on which
     the file resides.  However, a sparse file created with this
     command:
     打印实际大小, 而不是磁盘使用量。文件的实际大小是"wc -c"显示的普通文件的大小。
     或者是"ls -l --block-size=1", 亦或者是"stat --format=%s"。例如, 一个包含
     单词"zoo"但没有换行符的文件, 很明显它的大小是3。但是这么小的文件有可能占用
     0~16KiB或更多的磁盘空间, 取决于文件所在的文件系统的类型和配置。但是可以用这个
     命令来创建一个"稀疏文件":

          dd bs=1 seek=2GiB if=/dev/null of=big

     has an apparent size of 2 GiB, yet on most modern systems, it
     actually uses almost no disk space.
     它的实际大小是2GiB, 但在大多数现代系统中, 它实际上几乎不占用磁盘空间。

'-B SIZE'
'--block-size=SIZE'
     Scale sizes by SIZE before printing them (*note Block size::).  For
     example, '-BG' prints sizes in units of 1,073,741,824 bytes.
     打印前按SIZE缩放大小(*note Block size::)。例如, "-BG"以1,073,741,824 bytes为单位打印。

'-b'
'--bytes'
     Equivalent to '--apparent-size --block-size=1'.
     相当于"--apparent-size --block-size=1"。

'-c'
'--total'
     Print a grand total of all arguments after all arguments have been
     processed.  This can be used to find out the total disk usage of a
     given set of files or directories.
     在所有参数被处理后,打印所有参数的总计。这可以用来找出给定文件或目录集的总磁盘使用情况。

'-D'
'--dereference-args'
     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.
     取消作为命令行参数的符号链接的引用。不影响其他符号链接。这有助于找出目录的磁盘使用情况,
     例如'/usr/tmp', 通常是符号链接。

'-d DEPTH'
'--max-depth=DEPTH'
     Show the total for each directory (and file if -all) that is at
     most MAX_DEPTH levels down from the root of the hierarchy.  The
     root is at level 0, so 'du --max-depth=0' is equivalent to 'du -s'.
     显示从当前目录下最多DEPTH级的每个目录(以及选择全部目录)。根节点为0级,
     因此'du --max-depth=0'等价于'du -s'。

'--files0-from=FILE'
     Disallow processing files named on the command line, and instead
     process those named in file FILE; each name being terminated by a
     zero byte (ASCII NUL). This is useful when the list of file names
     is so long that it may exceed a command line length limitation.  In
     such cases, running 'du' via 'xargs' is undesirable because it
     splits the list into pieces and makes 'du' print with the '--total'
     ('-c') option for each sublist rather than for the entire list.
     One way to produce a list of ASCII NUL terminated file names is
     with GNU 'find', using its '-print0' predicate.  If FILE is '-'
     then the ASCII NUL terminated file names are read from standard
     input.
     不允许处理命令行上命名的文件,而是处理文件file中命名的文件;每个名称以零字节结束(ASCII NUL)。
     当文件名列表太长以至于可能超过命令行长度限制时,这很有用。在这种情况下,通过'xargs'运行'du'
     是不可取的,因为它会将列表分割成几块,并对每个子列表而不是整个列表使用'--total' ('-c')
     选项打印'du'。生成以NUL结尾的ASCII文件名列表的一种方法是使用GNU的'find',使用它的'-print0'
     谓词。如果FILE为'-',则从标准输入读取以NUL结尾的ASCII文件名。

'-H'
     Equivalent to '--dereference-args' ('-D').
     相当于"--dereference-args"("-D")。

'-h'
'--human-readable'
     Append a size letter to each size, such as 'M' for mebibytes.
     Powers of 1024 are used, not 1000; 'M' stands for 1,048,576 bytes.
     This option is equivalent to '--block-size=human-readable'.  Use
     the '--si' option if you prefer powers of 1000.
     在每个大小后面添加一个大小写字母,例如mebibytes的“M”。使用1024的幂,而不是1000;
     “M”代表1,048,576字节。此选项等价于'——block-size=人类可读'。如果您更喜欢1000的幂,
     请使用“--si”选项。

'--inodes'
     List inode usage information instead of block usage.  This option
     is useful for finding directories which contain many files, and
     therefore eat up most of the inodes space of a file system (see
     'df', option '--inodes').  It can well be combined with the options
     '-a', '-c', '-h', '-l', '-s', '-S', '-t' and '-x'; however, passing
     other options regarding the block size, for example '-b', '-m' and
     '--apparent-size', is ignored.
     列出inode使用信息,而不是块使用情况。这个选项对于查找包含很多文件的目录非常有用,
     因为这些目录会占用文件系统的大部分inodes空间(参见'df', option '--inodes')。
     很可以结合选项'-a','-c','-h','- l','-s','-S','- t'和'- x';但是,
     传递关于块大小的其他选项,例如'-b','-m'和'--apparent-size'会被忽略。

'-k'
     Print sizes in 1024-byte blocks, overriding the default block size
     (*note Block size::).  This option is equivalent to
     '--block-size=1K'.
     以1024字节块打印大小,覆盖默认的块大小(*note Block size::)。
     这个选项等价于--block-size=1K'。

'-L'
'--dereference'
     Dereference symbolic links (show the disk space used by the file or
     directory that the link points to instead of the space used by the
     link).
     解除符号链接引用(显示链接所指向的文件或目录所使用的磁盘空间,而不是该链接所使用的空间)。

'-l'
'--count-links'
     Count the size of all files, even if they have appeared already (as
     a hard link).
     计算所有文件的大小,即使它们已经出现(作为硬链接)。

'-m'
     Print sizes in 1,048,576-byte blocks, overriding the default block
     size (*note Block size::).  This option is equivalent to
     '--block-size=1M'.
     打印大小为1,048,576字节块,覆盖默认块大小(*note Block size::)。
     这个选项等价于'--block-size=1M'。

'-P'
'--no-dereference'
     For each symbolic links encountered by 'du', consider the disk
     space used by the symbolic link.
     对于'du'遇到的每个符号链接,考虑该符号链接使用的磁盘空间。

'-S'
'--separate-dirs'
     Normally, in the output of 'du' (when not using '--summarize'), the
     size listed next to a directory name, D, represents the sum of
     sizes of all entries beneath D as well as the size of D itself.
     With '--separate-dirs', the size reported for a directory name, D,
     will exclude the size of any subdirectories.
     通常,在'du'的输出中(当不使用'--summarize'时),目录名D旁边列出的大小表示D下面
     所有条目的大小之和以及D本身的大小。使用'--separate-dirs'时,目录名D报告的大小
     将排除任何子目录的大小。

'--si'
     Append an SI-style abbreviation to each size, such as 'M' for
     megabytes.  Powers of 1000 are used, not 1024; 'M' stands for
     1,000,000 bytes.  This option is equivalent to '--block-size=si'.
     Use the '-h' or '--human-readable' option if you prefer powers of
     1024.
     在每个大小后面添加SI-style的缩写,例如“M”表示兆字节。这里使用的是1000的幂,
     而不是1024;“M”代表1,000,000字节。这个选项等价于'--block-size=si'。
     如果你喜欢1024的幂,可以使用'-h'或'--human-readable'选项。

'-s'
'--summarize'
     Display only a total for each argument.
     只显示每个参数的总数。

'-t SIZE'
'--threshold=SIZE'
     Exclude entries based on a given SIZE.  The SIZE refers to used
     blocks in normal mode (*note Block size::), or inodes count in
     conjunction with the '--inodes' option.
     根据给定的SIZE排除条目。SIZE指的是在正常模式下使用的块(*note Block size::),
     或者与'--inodes'选项结合使用的inodes数量。

     If SIZE is positive, then 'du' will only print entries with a size
     greater than or equal to that.
     如果SIZE为正,则'du'将只打印大小大于或等于SIZE的条目。

     If SIZE is negative, then 'du' will only print entries with a size
     smaller than or equal to that.
     如果SIZE为负值,则'du'将只打印SIZE小于或等于该值的条目。

     Although GNU 'find' can be used to find files of a certain size,
     'du''s '--threshold' option can be used to also filter directories
     based on a given size.
     尽管GNU的“find”可以用于查找特定大小的文件,'du''s '--threshold'选项也可以
     用于基于给定大小的目录过滤。

     Please note that the '--threshold' option can be combined with the
     '--apparent-size' option, and in this case would elide entries
     based on its apparent size.
     请注意,“--threshold”选项可以与“--apparent-size”选项结合使用的情况下,
     将根据其外观大小删除条目。

     Please note that the '--threshold' option can be combined with the
     '--inodes' option, and in this case would elide entries based on
     its inodes count.
     请注意,'--threshold'选项可以与'--inodes'选项结合使用的情况下,
     将根据其inodes计数删除条目。

     Here's how you would use '--threshold' to find directories with a
     size greater than or equal to 200 megabytes:
     下面是如何使用'--threshold'查找大于或等于200兆字节的目录:

          du --threshold=200MB

     Here's how you would use '--threshold' to find directories and
     files - note the '-a' - with an apparent size smaller than or equal
     to 500 bytes:
     下面是使用'--threshold'查找目录和文件的方法(注意'-a')其大小小于等于500字节:

          du -a -t -500 --apparent-size

     Here's how you would use '--threshold' to find directories on the
     root file system with more than 20000 inodes used in the directory
     tree below:
     下面是如何使用'--threshold'在根文件系统中查找下面目录树中使用超过20000个索引节点的目录:

          du --inodes -x --threshold=20000 /

'--time'
     Show time of the most recent modification of any file in the
     directory, or any of its subdirectories.
     显示目录中任何文件或其子目录中任何文件最近修改的时间。

'--time=ctime'
'--time=status'
'--time=use'
     Show the most recent status change time (the 'ctime' in the inode)
     of any file in the directory, instead of the modification time.
     显示目录中任何文件最近的状态更改时间(inode中的'ctime'),而不是修改时间。

'--time=atime'
'--time=access'
     Show the most recent access time (the 'atime' in the inode) of any
     file in the directory, instead of the modification time.
     显示目录中任何文件最近的访问时间(inode中的'atime'),而不是修改时间。

'--time-style=STYLE'
     List timestamps in style STYLE.  This option has an effect only if
     the '--time' option is also specified.  The STYLE should be one of
     the following:
      此选项只有在同时指定了'--time'选项时才生效。风格应是下列之一:

     '+FORMAT'
          List timestamps using FORMAT, where FORMAT is interpreted like
          the format argument of 'date' (*note date invocation::).  For
          example, '--time-style="+%Y-%m-%d %H:%M:%S"' causes 'du' to
          list timestamps like '2002-03-30 23:45:56'.  As with 'date',
          FORMAT's interpretation is affected by the 'LC_TIME' locale
          category.
           例如,'--time-style="+%Y-%m-%d %H:% m:%S"'会使'du'列出类似于
           '2002-03-30 23:45:56'的时间戳。与'date'一样,FORMAT的解释受
           'LC_TIME'区域类别的影响。

     'full-iso'
          List timestamps in full using ISO 8601 date, time, and time
          zone format with nanosecond precision, e.g., '2002-03-30
          23:45:56.477817180 -0700'.  This style is equivalent to
          '+%Y-%m-%d %H:%M:%S.%N %z'.
          使用ISO 8601日期、时间和时区格式以纳秒精度完整列出时间戳,例如
          “2002-03-30 23:45:56.477817180-0700”。此样式相当于“+%Y-%m-%d%H:%m:%S.%N%z”。

     'long-iso'
          List ISO 8601 date and time in minutes, e.g., '2002-03-30
          23:45'.  These timestamps are shorter than 'full-iso'
          timestamps, and are usually good enough for everyday work.
          This style is equivalent to '+%Y-%m-%d %H:%M'.
          以分钟为单位列出ISO 8601日期和时间,例如“2002-03-30 23:45”。
          这些时间戳比“完整iso”时间戳短,通常足以用于日常工作。此样式相当于“+%Y-%m-%d%H:%m”。

     'iso'
          List ISO 8601 dates for timestamps, e.g., '2002-03-30'.  This
          style is equivalent to '+%Y-%m-%d'.
          列出时间戳的ISO 8601日期,例如“2002-03-30”。此样式相当于“+%Y-%m-%d”。

     You can specify the default value of the '--time-style' option with
     the environment variable 'TIME_STYLE'; if 'TIME_STYLE' is not set
     the default style is 'long-iso'.  For compatibility with 'ls', if
     'TIME_STYLE' begins with '+' and contains a newline, the newline
     and any later characters are ignored; if 'TIME_STYLE' begins with
     'posix-' the 'posix-' is ignored; and if 'TIME_STYLE' is 'locale'
     it is ignored.
     可以使用环境变量“--time-style”指定“TIME_STYLE”选项的默认值;如果未设置“TIME_STYLE”,
     则默认样式为“long-iso”。为了与“ls”兼容,如果“TIME_STYLE”以“+”开头并包含换行符,
     则该换行符和任何后续字符将被忽略;如果“TIME_STYLE”以“posix-”开头,则忽略“posix-”;
     如果“TIME_STYLE”是“locale”,则会被忽略。

'-X FILE'
'--exclude-from=FILE'
     Like '--exclude', except take the patterns to exclude from FILE,
     one per line.  If FILE is '-', take the patterns from standard
     input.
     比如“--exclude”,除了从文件中排除模式,每行一个。如果文件为“-”,则从标准输入中获取模式。

'--exclude=PATTERN'
     When recursing, skip subdirectories or files matching PATTERN.  For
     example, 'du --exclude='*.o'' excludes files whose names end in
     '.o'.
    递归时,跳过与模式匹配的子目录或文件。例如,“du--exclude='*.o'”不包括名称以“*.o”结尾的文件。

'-x'
'--one-file-system'
     Skip directories that are on different file systems from the one
     that the argument being processed is on.
     跳过与正在处理的参数所在的文件系统不同的文件系统上的目录。

   On BSD systems, 'du' reports sizes that are half the correct values
for files that are NFS-mounted from HP-UX systems.  On HP-UX systems, it
reports sizes that are twice the correct values for files that are
NFS-mounted from BSD systems.  This is due to a flaw in HP-UX; it also
affects the HP-UX 'du' program.
   在BSD系统上,“du”报告的大小是从HP-UX系统装入NFS的文件的正确值的一半。
   在HP-UX系统上,它报告的大小是从BSD系统装入NFS的文件的正确值的两倍。
   这是由于HP-UX中的一个缺陷造成的;这也会影响HP-UX的“du”程序。

   An exit status of zero indicates success, and a nonzero value
indicates failure.
   退出状态为零表示成功,非零值表示失败。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值