For faster navigation, this Iframe is preloading the Wikiwand page for du (Unix).

du (Unix)

终端中du的截图

du(disk usage的缩写,磁碟使用情况)是一个标准Unix程序,用于估量文件或文件夹的磁碟使用情况。

历史

[编辑]

du工具首次出现在AT&T Unix的第一版中。

规范

[编辑]

默认情况下,单一UNIX规范规定,du显示当前目录每个文件与目录的被分配磁碟空间的情况。链接文件将会显示其本身大小而非其链接对象;目录则会显示其内容的大小。

由于du只反映磁碟分配情况而非实际文件大小,所以如果文件被删除后磁碟未被释放,其显示的数字会与df报告的数字有所不同。

用法

[编辑]

du可以带一个参数,即指定一个路径来工作;如果没有指定,则使用当前目录。SUS指定了du有以下这些选项:

-a,显示所有的文件和目录,而不仅仅显示目录。
-H,计算命令行中指定链接对象的磁碟使用情况。
-k,将大小除以1024字节,而非512字节显示。
-L,计算任意链接对象的使用情况。
-s,仅汇报当前目录总计的磁碟使用情况,而不显示每一个文件。
-x,仅遍历指定路径所在装置上的文件与目录。

其他Unix和类Unix操作系统可能提供额外的选项。例如,BSDGNUdu规定了一个-h选项,把磁碟使用情况的大小加上单位后缀,显示为一个用户更容易理解的形式。(如:10MB)

示例

[编辑]

KB单位的目录总大小:

 $ du -sk *
 152304  directoryOne
 1856548 directoryTwo

更易读的目录总大小格式(Byte、KB、MB、GB、TB、PB):

 $ du -sh *
 149M directoryOne
 1.8G directoryTwo

当前目录下包含隐藏文件,子目录与文件的磁碟使用情况(从小到大排序):

 $ du -sk .[!.]* *| sort -n

当前目录下包含隐藏文件,子目录与文件的磁碟使用情况(从大到小排序):

 $ du -sk .[!.]* *| sort -nr

显示深度为1的目录大小及其总和

 $ du -d 1 -c -h

参考

[编辑]
  • Baobab

外部链接

[编辑]

使用手册

[编辑]

其他

[编辑]
{{bottomLinkPreText}} {{bottomLinkText}}
du (Unix)
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?