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 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.