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. thinkphp对数据库操作有哪些内置函数

    getModelName() 获取当前Model的名称 getTableName() 获取当前Model的数据表名称 switchModel(type,vars=array()) 动态切换模型 tab ...

  2. 不同的source control下配置DiffMerge

    TFS: 1. 打开Option -> Source Control -> Visual Studio TFS -> Configure User Tools; 2. 添加 .*, ...

  3. sqlserver2008 解决 ldf文件过大的方法

    SQL2008清空删除日志: '在SQL2008中清除日志就必须在简单模式下进行,等清除动作完毕再调回到完全模式. ------------------------------------------ ...

  4. bzoj 1295: [SCOI2009]最长距离 暴力+bfs最短路

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=1295 题解: 对每个点暴力跑一遍bfs,看能够到达的最远位置,这里如果有障碍物则距离为1 ...

  5. 安装 SQL SERVER PROFILER

    SQL SERVER 2008 R2 (10.50.40) 版本,安装 SQL SERVER PROFILER:通过 command prompt,使用以下命令:setup.exe /FEATURES ...

  6. epoll 知识总结

    poll/select/epoll 对比 http://www.cnblogs.com/apprentice89/p/3234677.html    ---有待继续学习 http://blog.chi ...

  7. LVS+Keepalived实现高可用集群

    LVS+Keepalived实现高可用集群来源: ChinaUnix博客 日期: 2009.07.21 14:49 (共有条评论) 我要评论 操作系统平台:CentOS5.2软件:LVS+keepal ...

  8. Interface Comparator

    int compare(T o1, T o2) Compares its two arguments for order. Returns a negative integer, zero, or a ...

  9. 主题:PageRank解释

    转自:http://www.iteye.com/topic/95079 PageRank解释 通过对由超过 50,000 万个变量和 20 亿个词汇组成的方程进行计算,PageRank 能够对网页的重 ...

  10. [STL]单词转换

    如果单词转换文件的内容是: 'em         themcuz         becausegratz      grateful i             Inah        nopos ...