The du
command is a standard Linux/Unix command that allows a user to gain disk usage information quickly. It is best applied to specific directories and allows many variations for customizing the output to meet your needs.
As with most commands, the user can take advantage of many options or flags. Also, like many Linux commands, most users only use the same two or three flags to meet their specific set of needs. The aim here is to introduce the basic flags that people use, but also to look at some that are less common in hopes of improving our use of du
. Let's first look at the standalone command, and then add in various options.
[tcarrigan@rhel article_submissions]$ du /home/tcarrigan/article_submissions/
12 /home/tcarrigan/article_submissions/my_articles
36 /home/tcarrigan/article_submissions/community_content
48 /home/tcarrigan/article_submissions/
You can see that there are three lines of output given by the basic command. The values on the far left are the disk usage, followed by the specific directory responsible for that usage. The bottom row is a summary of the entire /home/tcarrigan/article_submissions
directory. There is no indication as to what unit of measure is being used with the standard command, making this output less than useful. Here is where the options become necessary.
[ Want to learn more about Linux? Free online course: Red Hat Enterprise Linux technical overview. ]
-h , --human-readable
The -h
flag prints size outputs, such as the ones above, in a human-readable format. This format provides a unit of measure (Bytes). If we now run the du -h
command on the same directory, we see that the 12, 36, and 48 values are in KB.
[tcarrigan@rhel article_submissions]$ du -h /home/tcarrigan/article_submissions/
12K /home/tcarrigan/article_submissions/my_articles
36K /home/tcarrigan/article_submissions/community_content
48K /home/tcarrigan/article_submissions/
-s, --summarize
The -s
flag is added to the -h
flag on occasion. With their powers combined, they do not become an eco-friendly demi-god. Instead, they allow us to get a summary of the directory's usage in a human-readable format.
[tcarrigan@rhel article_submissions]$ du -sh /home/tcarrigan/article_submissions/
48K /home/tcarrigan/article_submissions/
If that output seems familiar, its because its an exact copy of the last line of the -h
output.
-a, --all
This helpful option does exactly what you would think. It lists the sizes of all files and directories in the given file path. The -a
option is often combined with the -h
flag for ease of use. Notice the individual file sizes are listed with the directories.
[tcarrigan@rhel article_submissions]$ du -ah /home/tcarrigan/article_submissions/
8.0K /home/tcarrigan/article_submissions/my_articles/Creating_physical_volumes
4.0K /home/tcarrigan/article_submissions/my_articles/Creating_volume_groups
12K /home/tcarrigan/article_submissions/my_articles
4.0K /home/tcarrigan/article_submissions/community_content/article
4.0K /home/tcarrigan/article_submissions/community_content/article2
4.0K /home/tcarrigan/article_submissions/community_content/article3
4.0K /home/tcarrigan/article_submissions/community_content/article4
12K /home/tcarrigan/article_submissions/community_content/real_sysadmins
8.0K /home/tcarrigan/article_submissions/community_content/podman_pulling
36K /home/tcarrigan/article_submissions/community_content
48K /home/tcarrigan/article_submissions/
--time
I especially love this flag. It shows the time of the last modification to any file in the directory or subdirectory that you run it against. This flag was incredibly useful to me as a storage admin. On more than one occasion, I would have a customer write files to a subdirectory on accident, and then we needed to find where the write took place. I could use this flag in conjunction with the -ah
flags to find the directory last modified.
[tcarrigan@rhel article_submissions]$ du -ah --time /home/tcarrigan/article_submissions/
8.0K 2020-04-07 11:30 /home/tcarrigan/article_submissions/my_articles/Creating_physical_volumes
4.0K 2020-04-07 11:31 /home/tcarrigan/article_submissions/my_articles/Creating_volume_groups
12K 2020-04-07 11:31 /home/tcarrigan/article_submissions/my_articles
4.0K 2020-02-06 16:47 /home/tcarrigan/article_submissions/community_content/article
4.0K 2020-02-06 16:48 /home/tcarrigan/article_submissions/community_content/article2
4.0K 2020-02-06 16:48 /home/tcarrigan/article_submissions/community_content/article3
4.0K 2020-02-06 16:48 /home/tcarrigan/article_submissions/community_content/article4
12K 2020-04-07 11:32 /home/tcarrigan/article_submissions/community_content/real_sysadmins
8.0K 2020-04-07 11:32 /home/tcarrigan/article_submissions/community_content/podman_pulling
36K 2020-04-07 11:32 /home/tcarrigan/article_submissions/community_content
48K 2020-04-07 11:32 /home/tcarrigan/article_submissions/
Note: This does not sort by last modification so you still need to pay attention to the times. The last modification is not always at the top
-c, --total
This option is more of a dummy check than it is useful, however, some people really like having a total measurement output. The -c
flag adds a line to the bottom of the output that gives you a grand total of all of the disk usage for the file path given.
[tcarrigan@rhel article_submissions]$ du -ch /home/tcarrigan/article_submissions/
12K /home/tcarrigan/article_submissions/my_articles
36K /home/tcarrigan/article_submissions/community_content
48K /home/tcarrigan/article_submissions/
48K total
Notice the bottom line here. The same information is displayed that is shown in the other examples of du
but without the 'total' banner to remind you.
-X, --exclude=Pattern
The -X
option is a nifty little trick you can do if you know that your environment has a large number of a certain type of file that you do not wish to calculate in your findings. In my experience, certain customers would have large amounts of metadata files with the same file extension and did not wish to include those in their findings. I cannot demonstrate this here on my virtual machine; however, here is the syntax and an example.
[tcarrigan@rhel]$ du -ah --exclude="*.dll" /home/tcarrigan/article_submissions
This command would list all files and directory usage info in a human-readable format while excluding any file with the extension .dll. This is a bit niche, however, it does have a place in the world.
Wrap up and man page
Hopefully, you now have a better understanding how useful the du
utility can be. It is easy to get into the routine of only ever running du -h
and forgetting about all of the other incredibly powerful flags you have at your disposal. There are many flags that I did not cover in this article, but you can find all the information on the manual page for this command. To access the manpage, simply run man du
.
[ Want to test your sysadmin skills? Take a skills assessment today. ]
執筆者紹介
Tyler is the Sr. Community Manager at Enable Sysadmin, a submarine veteran, and an all-round tech enthusiast! He was first introduced to Red Hat in 2012 by way of a Red Hat Enterprise Linux-based combat system inside the USS Georgia Missile Control Center. Now that he has surfaced, he lives with his wife and son near Raleigh, where he worked as a data storage engineer before finding his way to the Red Hat team. He has written numerous technical documents, from military procedures to knowledgebase articles and even some training curricula. In his free time, he blends a passion for hiking, climbing, and bushcraft with video games and computer building. He is loves to read and enjoy a scotch or bourbon. Find him on Twitter or on LinkedIn.
類似検索
チャンネル別に見る
自動化
テクノロジー、チームおよび環境に関する IT 自動化の最新情報
AI (人工知能)
お客様が AI ワークロードをどこでも自由に実行することを可能にするプラットフォームについてのアップデート
オープン・ハイブリッドクラウド
ハイブリッドクラウドで柔軟に未来を築く方法をご確認ください。
セキュリティ
環境やテクノロジー全体に及ぶリスクを軽減する方法に関する最新情報
エッジコンピューティング
エッジでの運用を単純化するプラットフォームのアップデート
インフラストラクチャ
世界有数のエンタープライズ向け Linux プラットフォームの最新情報
アプリケーション
アプリケーションの最も困難な課題に対する Red Hat ソリューションの詳細
オリジナル番組
エンタープライズ向けテクノロジーのメーカーやリーダーによるストーリー
製品
ツール
試用、購入、販売
コミュニケーション
Red Hat について
エンタープライズ・オープンソース・ソリューションのプロバイダーとして世界をリードする Red Hat は、Linux、クラウド、コンテナ、Kubernetes などのテクノロジーを提供しています。Red Hat は強化されたソリューションを提供し、コアデータセンターからネットワークエッジまで、企業が複数のプラットフォームおよび環境間で容易に運用できるようにしています。
言語を選択してください
Red Hat legal and privacy links
- Red Hat について
- 採用情報
- イベント
- 各国のオフィス
- Red Hat へのお問い合わせ
- Red Hat ブログ
- ダイバーシティ、エクイティ、およびインクルージョン
- Cool Stuff Store
- Red Hat Summit