du【コマンド】
コマンドだよ
UNIX系で使えるよ
ディスク使用量を表示するよ
スポンサーリンク
簡単に書くよ
du【コマンド】とは
コンピュータさんに対する命令文(コマンド)のひとつ
であり
ファイルやディレクトリのディスク使用量を確認するときに使うコマンド
です。
詳しく書くよ
「du」コマンドは
ディスク使用量を確認するときに使うコマンド
です。
ファイルやディレクトリに対する「おまえは、どれだけ場所取ってるの?」を確認できます。
「du」コマンドはUNIX系(LinuxとかMacとか)で使えます。
書き方は
du [オプション] [対象のファイル or ディレクトリ]
です。
オプションは、あれやこれやとあります。
| オプション | 説明 |
|---|---|
| -0 | 改行しない end each output line with 0 byte rather than newline |
| --null | 改行しない end each output line with 0 byte rather than newline |
| -a | ファイルも表示する write counts for all files, not just directories |
| --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 【サイズ】 | 指定したブロックサイズで表示する scale sizes by SIZE before printing them; e.g., '-BM' prints sizes in units of 1,048,576 bytes; see SIZE format below |
| --block-size=【サイズ】 | 指定したブロックサイズで表示する scale sizes by SIZE before printing them; e.g., '-BM' prints sizes in units of 1,048,576 bytes; see SIZE format below |
| -b | サイズをバイト(Byte)単位で表示する equivalent to '--apparent-size --block-size=1' |
| --bytes | サイズをバイト(Byte)単位で表示する equivalent to '--apparent-size --block-size=1' |
| -c | 合計も表示する produce a grand total |
| --total | 合計も表示する produce a grand total |
| -D | シンボリックリンクは参照先のファイルの容量を表示する dereference only symlinks that are listed on the command line |
| --dereference-args | シンボリックリンクは参照先のファイルの容量を表示する dereference only symlinks that are listed on the command line |
| -d 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 |
| --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 |
| --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 |
| -H | 「-D」オプションと同じ equivalent to --dereference-args (-D) |
| -h | 人間様が見やすいように表示してやるよ print sizes in human readable format (e.g., 1K 234M 2G) |
| --human-readable | 人間様が見やすいように表示してやるよ print sizes in human readable format (e.g., 1K 234M 2G) |
| --inodes | list inode usage information instead of block usage |
| -k | 単位をキロバイト表示にする。「--block-size=1K」を指定したのと一緒 like --block-size=1K |
| -L | すべてのシンボリックリンクに対して参照先のファイルの容量を表示する dereference all symbolic links |
| --dereference | すべてのシンボリックリンクに対して参照先のファイルの容量を表示する dereference all symbolic links |
| -l | ハードリンクでもうんちゃらかんちゃら count sizes many times if hard linked |
| --count-links | ハードリンクでもうんちゃらかんちゃら count sizes many times if hard linked |
| -m | 単位をメガバイト表示にする。「--block-size=1M」を指定したのと一緒 like --block-size=1M |
| -P | シンボリックリンクはサイズ0として扱う。参照先のファイルを見ないよ don't follow any symbolic links (this is the default) |
| --no-dereference | シンボリックリンクはサイズ0として扱う。参照先のファイルを見ないよ don't follow any symbolic links (this is the default) |
| -S | サブディレクトリの容量を含めないで分けて表示する for directories do not include size of subdirectories |
| --separate-dirs | サブディレクトリの容量を含めないで分けて表示する for directories do not include size of subdirectories |
| -si | 「-h」と似たようなもの。人間様が見やすいように表示してやるよ。あと1キロバイトは1024バイトじゃなくて1000バイト扱いな like -h, but use powers of 1000 not 1024 |
| -s | 合計だけ表示するわ display only a total for each argument |
| --summarize | 合計だけ表示するわ display only a total for each argument |
| -t 【サイズ】 | exclude entries smaller than SIZE if positive, or entries greater than SIZE if negative |
| --threshold=【サイズ】 | exclude entries smaller than SIZE if positive, or entries greater than SIZE if negative |
| --time | 最終更新日時も表示してやるよ show time of the last modification of any file in the directory, or any of its subdirectories |
| --time=【種類】 | 指定した種類の日時も表示してやるよ。「atime」「access」「use」「ctime」「status」から好きなの指定しろ show time as WORD instead of modification time: atime, access, use, ctime or status |
| --time-style=【スタイル】 | [--time」で指定して表示する日付の書式を指定しやがれ show times using STYLE, which can be: full-iso, long-iso, iso, or +FORMAT; FORMAT is interpreted like in 'date' |
| -X 【ファイル】 | ファイルに書いてあるやつは除外してね exclude files that match any pattern in FILE |
| --exclude-from=【ファイル】 | ファイルに書いてあるやつは除外してね exclude files that match any pattern in FILE |
| --exclude=【パターン】 | 【パターン】に一致したやつは除外してね exclude files that match PATTERN |
| -x | 違うファイルシステムのやつは飛ばせや skip directories on different file systems |
| --one-file-system | 違うファイルシステムのやつは飛ばせや skip directories on different file systems |
| --help | ヘルプを表示する display this help and exit |
| --version | バージョン情報を表示する output version information and exit |
などです。
それでは、使い方を見ていきましょう。
オプションや対象を指定しないで
du
を実行すると、自分が今いるディレクトリのディスク使用量が表示されます。
私の環境では以下のように表示されました。
4 ./dir1
44 .
対象を指定して実行すると、対象のファイルやディレクトリのディスク使用量が表示されます。
例えば
du hoge.txt
を指定すると「hoge.txt」のディスク使用量が表示されます。
私の環境では以下のように表示されました。
4 hoge.txt
ディレクトリを指定した場合は、サブディレクトリも対象になります。
私の環境で
du ./
を指定して実行したところ、以下のように表示されました。
4 ./dir1
44 .
今いるディレクトリの中に「dir1」というサブディレクトリがあるのですが、それも表示されています。
「-a」オプションを指定すると、ファイルも表示されます。
私の環境で
du -a
を実行したところ、以下の結果になりました。
4 ./.bash_logout
4 ./.bash_profile
4 ./.bashrc
4 ./.cshrc
4 ./.tcshrc
4 ./anaconda-ks.cfg
0 ./.Xauthority
8 ./.bash_history
4 ./hoge.txt
0 ./ln_hoge
4 ./dir1/aaa.txt
4 ./dir1
44 .
「-a」オプションを指定することによって、ファイルも表示されていますよね。
「-c」オプションを指定すると、合計も表示されます。
私の環境で
du -c
を実行したところ、以下の結果になりました。
4 ./dir1
44 .
44 合計
「-c」オプションを指定することによって「合計」欄が追加されました。
「-D」オプションを指定すると、シンボリックリンクに対して、参照先のファイルの容量を表示します。
例えば、hoge.txtに対するシンボリックリンク「ln_hoge」が あったとしましょう。
ls -l ln_hoge
を実行すると
lrwxrwxrwx. 1 root root 8 1月 5 00:21 ln_hoge -> hoge.txt
と表示されます。
この状態で、単純に
du ln_hoge
を実行すると、結果は
0 ln_hoge
になりました。
使用量の数字が「0」になっています。
それに対して「-D」オプションを指定して
du -D ln_hoge
を実行すると、結果は
4 ln_hoge
になりました。
使用量の「4」はシンボリックリンクの参照先であるhoge.txtの使用量と同じです。
「--time」オプションを指定すると、最終更新日時も表示されます。
私の環境で
du --time
を実行したところ、以下の結果になりました。
4 2016-01-05 00:53 ./dir1
44 2016-01-05 00:55 .
基本的な使い方は、そんなところでしょうか。
あとは必要に応じて、オプションなどの情報を補完してください。
一言でまとめるよ
まぁ「du」ってコマンドが出てきたら「ディスク使用量を確認するときに使うんだな~」と お考えください。
おまけ
■訳してみるよ
「du」は「disk usage(ディスク・ユーセージ)」の略らしいです。
「disk(ディスク)」の意味は「円盤」とか「薄い円盤状のもの」とかです。
「usage(ユーセージ)」の意味は「使用」とか「使用法」とか「使用量」とかです。
何となく くっつけると
円盤の使用量
となります。
■検索してみる?






