The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of disk usage of files and directories on a machine. The du command has many parameter options that can be used to get the results in many formats. The du command also displays the files and directory sizes in a recursively manner.

Check Disk Usage of Files and Folders In Linux

This article explains 10 useful “du” commands with
their examples, that might helps you to find out the sizes of files and
directories in Linux. The information provided in this article are taken
from the man pages of du command.

Read Also:

  1. 12 “df” Command to Check Linux System Disk Space

1. To find out the disk usage summary of a /home/tecmint directory tree and each of its sub directories. Enter the command as:

[root@tecmint]# du  /home/tecmint

40      /home/tecmint/downloads
4 /home/tecmint/.mozilla/plugins
4 /home/tecmint/.mozilla/extensions
12 /home/tecmint/.mozilla
12 /home/tecmint/.ssh
689112 /home/tecmint/Ubuntu-12.10
689360 /home/tecmint

The output of the above command displays the number of disk blocks in the /home/tecmint directory along with its sub-directories.

2. Using “-h” option with “du” command provides results in “Human Readable Format“. Means you can see sizes in Bytes, Kilobytes, Megabytes, Gigabytes etc.

[root@tecmint]# du -h /home/tecmint

40K     /home/tecmint/downloads
4.0K /home/tecmint/.mozilla/plugins
4.0K /home/tecmint/.mozilla/extensions
12K /home/tecmint/.mozilla
12K /home/tecmint/.ssh
673M /home/tecmint/Ubuntu-12.10
674M /home/tecmint

3. To get the summary of a grand total disk usage size of an directory use the option “-s” as follows.

[root@tecmint]# du -sh /home/tecmint

674M    /home/tecmint

4. Using “-a” flag with “du” command displays the disk usage of all the files and directories.

[root@tecmint]# du -a /home/tecmint

4       /home/tecmint/.bash_logout
12 /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24 /home/tecmint/downloads/Phpfiles-org.tar.bz2
40 /home/tecmint/downloads
12 /home/tecmint/uploadprogress-1.0.3.1.tgz
4 /home/tecmint/.mozilla/plugins
4 /home/tecmint/.mozilla/extensions
12 /home/tecmint/.mozilla
4 /home/tecmint/.bashrc
689108 /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
689112 /home/tecmint/Ubuntu-12.10
689360 /home/tecmint

5. Using “-a” flag along with “-h” displays disk usage of all files and folders in human readeable format. The below output is more easy to understand as it shows the files in Kilobytes, Megabytes etc.

[root@tecmint]# du -ah /home/tecmint

4.0K    /home/tecmint/.bash_logout
12K /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24K /home/tecmint/downloads/Phpfiles-org.tar.bz2
40K /home/tecmint/downloads
12K /home/tecmint/uploadprogress-1.0.3.1.tgz
4.0K /home/tecmint/.mozilla/plugins
4.0K /home/tecmint/.mozilla/extensions
12K /home/tecmint/.mozilla
4.0K /home/tecmint/.bashrc
673M /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M /home/tecmint/Ubuntu-12.10
674M /home/tecmint

6. Find out the disk usage of a directory tree with its subtress in Kilobyte blcoks. Use the “-k” (displays size in 1024 bytes units).

[root@tecmint]# du -k /home/tecmint
40 /home/tecmint/downloads
4 /home/tecmint/.mozilla/plugins
4 /home/tecmint/.mozilla/extensions
12 /home/tecmint/.mozilla
12 /home/tecmint/.ssh
689112 /home/tecmint/Ubuntu-12.10
689360 /home/tecmint

7. To get the summary of disk usage of directory tree along with its subtrees in Megabytes (MB) only. Use the option “-mh” as follows. The “-m” flag counts the blocks in MB units and “-h” stands for human readable format.

[root@tecmint]# du -mh /home/tecmint

40K     /home/tecmint/downloads
4.0K /home/tecmint/.mozilla/plugins
4.0K /home/tecmint/.mozilla/extensions
12K /home/tecmint/.mozilla
12K /home/tecmint/.ssh
673M /home/tecmint/Ubuntu-12.10
674M /home/tecmint

8. The “-c” flag provides a grand total usage disk space at the last line. If your directory taken 674MB space, then the last last two line of the output would be.

[root@tecmint]# du -ch /home/tecmint

40K     /home/tecmint/downloads
4.0K /home/tecmint/.mozilla/plugins
4.0K /home/tecmint/.mozilla/extensions
12K /home/tecmint/.mozilla
12K /home/tecmint/.ssh
673M /home/tecmint/Ubuntu-12.10
674M /home/tecmint
674M total

9. The below command calculates and displays the disk usage of all files and directories, but excludes the files that matches given pattern. The below command excludes the “.txt” files while calculating the total size of diretory. So, this way you can exclude any file formats by using flag “-–exclude“. See the output there is no txt files entry.

[root@tecmint]# du -ah --exclude="*.txt" /home/tecmint

4.0K    /home/tecmint/.bash_logout
12K /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24K /home/tecmint/downloads/Phpfiles-org.tar.bz2
40K /home/tecmint/downloads
12K /home/tecmint/uploadprogress-1.0.3.1.tgz
4.0K /home/tecmint/.bash_history
4.0K /home/tecmint/.bash_profile
4.0K /home/tecmint/.mozilla/plugins
4.0K /home/tecmint/.mozilla/extensions
12K /home/tecmint/.mozilla
4.0K /home/tecmint/.bashrc
24K /home/tecmint/Phpfiles-org.tar.bz2
4.0K /home/tecmint/geoipupdate.sh
4.0K /home/tecmint/.zshrc
120K /home/tecmint/goaccess-0.4.2.tar.gz.1
673M /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M /home/tecmint/Ubuntu-12.10
674M /home/tecmint

10. Display the disk usage based on modification of time, use the flag “–time” as shown below.

[root@tecmint]# du -ha --time /home/tecmint

4.0K    2012-10-12 22:32        /home/tecmint/.bash_logout
12K 2013-01-19 18:48 /home/tecmint/downloads/uploadprogress-1.0.3.1.tgz
24K 2013-01-19 18:48 /home/tecmint/downloads/Phpfiles-org.tar.bz2
40K 2013-01-19 18:48 /home/tecmint/downloads
12K 2013-01-19 18:32 /home/tecmint/uploadprogress-1.0.3.1.tgz
4.0K 2012-10-13 00:11 /home/tecmint/.bash_history
4.0K 2012-10-12 22:32 /home/tecmint/.bash_profile
0 2013-01-19 18:32 /home/tecmint/xyz.txt
0 2013-01-19 18:32 /home/tecmint/abc.txt
4.0K 2012-10-12 22:32 /home/tecmint/.mozilla/plugins
4.0K 2012-10-12 22:32 /home/tecmint/.mozilla/extensions
12K 2012-10-12 22:32 /home/tecmint/.mozilla
4.0K 2012-10-12 22:32 /home/tecmint/.bashrc
24K 2013-01-19 18:32 /home/tecmint/Phpfiles-org.tar.bz2
4.0K 2013-01-19 18:32 /home/tecmint/geoipupdate.sh
4.0K 2012-10-12 22:32 /home/tecmint/.zshrc
120K 2013-01-19 18:32 /home/tecmint/goaccess-0.4.2.tar.gz.1
673M 2013-01-19 18:51 /home/tecmint/Ubuntu-12.10/ubuntu-12.10-server-i386.iso
673M 2013-01-19 18:51 /home/tecmint/Ubuntu-12.10

10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories的更多相关文章

  1. [FAILED]Marking disk "DATA02" as an ASM disk

    执行删除asm磁盘时报错! [root@rac1 grid]# /etc/init.d/oracleasm deletedisk DATA01 /dev/sdc1 Marking disk " ...

  2. drop asm disk、撤销drop asm disk

    drop asm disk.撤销drop asm disk drop asm disk:SQL> alter diskgroup XXX offline disk XXXX drop after ...

  3. 12 Useful “df” Commands to Check Disk Space in Linux

    On the internet you will find plenty of tools for checking disk space utilization in Linux. However, ...

  4. 5 commands to check memory usage on Linux

    Memory Usage On linux, there are commands for almost everything, because the gui might not be always ...

  5. Xcode7 运行iOS10以上系统(10.1、10.2、10.3)解决Could not find Developer Disk Image

    由于历史原因,需要在Xcode7上真机运行下app,无奈手机系统已是10.3了,一运行, 就提示:Could not find Developer Disk Image 解决办法: 1.找到xcode ...

  6. 10.使用du将文件按大小进行排序

    按G进行排序du -sh * | grep G | sort -nr

  7. windows 10安装docker一直挂起在Installing Components and Removing Files

    碰到这个问题百度了好久都没有找到解决方式,什么用管理员方式运行,给文件夹权限啊,都不好使. 后面在bing上面搜docker install compoents关键字找到一条结果,如下如 点进链接,内 ...

  8. 手工创建ASM Disk Groups、为 ASM Disk Groups 添加 disk

    Groups 添加 disk 创建语法说明: 必选参数: (1) 指定disk group 的唯一名称 (不分区大小写) (2) 指定disk group 的冗余级别对于ASM 的镜像冗余,可以指定3 ...

  9. 真机调试报错:Could not find Developer Disk Image 或 Could not locate device support files.

    废话不多说,原因是用的Xcode版本所支持的最高iOS系统低于真机iOS系统导致. 解决方案: 1.升级到最新的Xcode版本 2.不想升级Xcode,那就找已经把Xcode升级到最新版本的朋友,发给 ...

随机推荐

  1. cocos2dx中创建动画的三种方法

    1.最最原始的方法,先创建动画帧,再创建动画打包(animation),再创建动画(animate) 第一步: 创建动画帧:CCSpriteFrame,依赖于原始的资源图片(xx.png,xx.jpg ...

  2. Sublime key bindings使用

    开启vi mode后,可以使用很多的VI快捷方式,所以我的sublime已经不是单纯的st了,st的VI模式不完全支持所有的快捷键.我们来看一段官网的key bindings示例: { "k ...

  3. html+css学习笔记 3[浮动]

    inline-block/float(浮动) 回顾:inline-block 特性:      1.块在一排显示 2.内联支持宽高 3.默认内容撑开宽度 4.标签之间的换行间隙被解析(问题) 5.ie ...

  4. java递归查询方法

    一.需求 项目里要让用户能够设置所选择教材的章课节,以针对章课节提供相应的题目供用户做题. 设计:用户设置了教材后,首次登录,进行章节设置时.默认为用户选择第一章.第一课.第一节. 思路:用户访问页面 ...

  5. [设计模式] 13 责任链模式 Chain of Responsibility

    转    http://blog.csdn.net/wuzhekai1985   http://www.jellythink.com/archives/878 向项目经理提交了休假申请,我的项目经理向 ...

  6. Windows 进程通信 之 DDE技术

    DDE (Dynamic Data Exchange,DDE)动态数据交换,是一种进程间通信机制,它最早是随着Windows由微软提出的.当前大部分软件仍旧支持DDE,但最近十年里微软已经停止发展DD ...

  7. 15个实用的jQuery技术

    JQuery是目前最流行的JavaScript框架之一,可以显著的提高用户与网络应用的交互. 今天为大家介绍50有用的jQuery技术: 1.移动Box 2.滑动框和标题 3.数据的可视化:使用HTM ...

  8. 原 Linux搭建SVN 服务器2

    原 Linux搭建SVN 服务器 发表于1年前(2014-08-05 17:55)   阅读(12257) | 评论(3) 31人收藏此文章, 我要收藏 赞3 摘要 Linux搭建SVN 服务器 目录 ...

  9. Candy

    There are N children standing in a line. Each child is assigned a rating value. You are giving candi ...

  10. POJ3267The Cow Lexicon

    http://poj.org/problem?id=3267 题意 : 给你一个message,是给定字符串,然后再给你字典,让你将message与字典中的单词进行匹配,输出要删掉多少字母. 思路 : ...