コンテンツにスキップ

利用者:angol Mois/sandbox


duコマンドの出力例

dudisk usage)とは、UNIXの、ディレクトリファイルファイルシステムのサイズの大きさを表示する基本的なプログラムである。

歴史[編集]

duコマンドはAT&T UNIXのバージョン1に初めて現れた。

仕様[編集]

デフォルトでは、duSingle UNIX Specification (SUS) の通り、カレントディレクトリ内の各ファイルのサイズを表示するという仕様である。リンクはリンクファイルとしてのサイズが表示され、リンク先のファイルのサイズを表示するわけではない。

duコマンドはファイルの絶対的なサイズではなく割り当てられたスペースを表示するので、ファイルが削除されていてもそのブロックが解放されていなければdfの表示と異なる場合がある。ファイルシステムのデータブロックを割り当てる最低限の空きページ数の設定と、ルートユーザーのプロセスは、実際に使われているブロックの合計と割り当てられたブロックの間に差を生む。この最低限の空きページ数の設定は大体、ファイルシステム全体の5%になっている。より詳しい説明は、GNUのFAQ (英語)を参照のこと。

使い方[編集]

du は一つの引数とファイルのパスを取る。ファイルのパスを指定しなかった場合、カレントディレクトリが適応される。引数は次の通り。

-a, In addition to the default output, include information for each non-directory entry
-c, display a grand total of the disk usage found by the other arguments
-d #, the depth at which summing should occur. -d 0 sums at the current level, -d 1 sums at the subdirectory, -d 2 at sub-subdirectories, etc.
-H, calculate disk usage for link references specified on the command line
-k, show sizes as multiples of 1024 bytes, not 512-byte
-L, calculate disk usage for link references anywhere
-s, report only the sum of the usage in the current directory, not for each file
-x, only traverse files and directories on the device on which the pathname argument is specified.

Other Unix and Unix-like operating systems may add extra options. For example, BSD and GNU du specify a -h option, displaying disk usage in a format easier to read by the user, adding units with the appropriate SI prefix (e.g. 10 MB)..

出力例[編集]

キロバイト単位でのディレクトリの合計サイズ (-s)

$ du -sk *
152304  directoryOne
1856548 directoryTwo

Sum of directories (-s) in human-readable format (-h : Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte):

$ du -sh *
149M directoryOne
1.8G directoryTwo

disk usage of all subdirectories and files including hidden files within the current directory (sorted by filesize) :

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

disk usage of all subdirectories and files including hidden files within the current directory (sorted by reverse filesize) :

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

The weight (size) of each subdirectory under the current directory (-d 1) with a sum total at the end (-c) all displayed in human-readable format (-h):

 $ du -d 1 -c -h

or with du from GNU:

 $ du --max-depth=1 -c -h

The weight (size) of subdirectories under the root directory (-d 1, trailing /) with a sum total at the end (-c), all displayed in human-readable format (-h) without traversing into other filesystems (-x). Useful when /var /tmp or other directories are on separate storage from the root directory:

 $ du -d 1 -c -h -x /

or with du from GNU:

 $ du --max-depth=1 -c -h -x /

関連項目[編集]

外部リンク[編集]

  • du: estimate file space usage – The Open Group基本仕様書第7号2018年版「シェル及びユーティリティ」

マニュアル[編集]

Template:Disk space analyzers Template:Unix commands