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. android 开发edittext获取焦点时hint消失

    默认情况时:设置了hint的话,需要输入的时候hint才会消失,但是现在是需要当edittext获取焦点时就让hint消失 代码如下: verifycode= (EditText)findViewBy ...

  2. ACCESS数据库C#操作类(包含事务)

    转自http://blog.csdn.net/allen3010/article/details/6336717 这个是针对ACCESS数据库操作的类,同样也是从SQLHELPER提取而来,分页程序的 ...

  3. java集合类(六)About Queue

    接上篇“java集合类(五)About Map” 终于来到了java集合类的尾声,太兴奋了,不是因为可以休息一阵了,而是因为又到了开启新知识的时刻,大家一起加油打气!!Come on...Fighti ...

  4. Timer 的缺陷

    java.util.Timer计时器有管理任务延迟执行("如1000ms后执行任务")以及周期性执行("如每500ms执行一次该任务").但是,Timer存在一 ...

  5. 常用git 命令

    1.取消跟踪某些文件或文件夹: 删除文件: $git rm --cached FILENAME 删除文件夹: $git rm -r --cached Path 2.忽略某些文件或文件夹 $vi .gi ...

  6. 【BZOJ】【2194】快速傅里叶之二

    FFT c[k]=sigma a[i]*b[i-k] 这个形式不好搞…… 而我们熟悉的卷积的形式是这样的 c[k]=sigma a[i]*b[k-i]也就是[下标之和是定值] 所以我们将a数组反转一下 ...

  7. oracle中行转列函数

    一.问题描述 有时在“相关子查询中”需要查询某个实体类对应的某个字段有多个值,如果不做行专列查询,会提示返回多个列的错误.例如: 如上图所示,一个组合包,可能对应多个产品,需要你将所对应的多个产品都放 ...

  8. BestCoder Round #3

    Task schedule http://acm.hdu.edu.cn/showproblem.php?pid=4907 #include<cstdio> #include<cstr ...

  9. hdu 4324 Triangle LOVE(拓扑排序,基础)

    题目 /***************************参考自****************************/ http://www.cnblogs.com/newpanderking ...

  10. C#委托及事件

    转载:http://www.cnblogs.com/warensoft/archive/2010/03/19/1689806.html C#委托及事件 在C#中,委托(delegate)是一种引用类型 ...