10 Useful du (Disk Usage) Commands to Find Disk Usage of Files and Directories

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
674M 2013-01-19 18:52 /home/tecmint

Read Also :

  1. 10 fdisk Commands to Manage Linux Disk Partitions
  2. 12 Useful “df” Commands to Check Disk Space in Linux

【转载】10个有用的du命令行的更多相关文章

  1. 转: windows 10使用原生linux bash命令行

    转: https://www.zybuluo.com/pandait/note/337430 windows 10使用原生linux bash命令行 linux bash windows-10 第一时 ...

  2. 有用的 Mongo命令行 db.currentOp() db.collection.find().explain() - 摘自网络

    在Heyzap 和 Bugsnag 我已经使用MongoDB超过一年了,我发现它是一个非常强大的数据库.和其他的数据库一样,它有一些缺陷,但是这里有一些东西我希望有人可以早一点告诉我的. 即使建立索引 ...

  3. lua学习笔记10:lua简单的命令行

    前面反复使用的命令行,好学喜欢命令行: 一 格公式 lua [options][script][args] 两 详细命令 -e 直接命令传递一个lua -l 加载文件 -i 进入交互模式 比例如.端子 ...

  4. 随笔编号-10 window环境下,命令行导入sql脚本详解

    目标:使用window命令行(DOS)导入sql脚本(适用于数据量很大的脚本). 执行步骤: 1  找到mysql bin 文件所在之目录: 2  打开dos命令行界面,win+r 组合键打开运行对话 ...

  5. 【转载】在LoadRunner中执行命令行程序之:popen()取代system()

    我想大家应该都知道在LoadRunner可以使用函数system()来调用系统指令,结果同在批处理里执行一样. 但是system()有个缺陷:无法获取命令的返回结果. 也许你可以用`echo comm ...

  6. 20个有用的linux命令行技巧

    20 Unix Command Line Tricks – Part I http://www.cyberciti.biz/open-source/command-line-hacks/20-unix ...

  7. 【转载】OPENWRT入门之四------openwrt命令行模式命令及其工具

    连接来源http://bbs.xiaomi.cn/thread-9734746-1-1.html 需要学会用ssh登录路由器用linux命令查看.ps 命令查看当前系统运行的进程信息free 命令查看 ...

  8. 10. 通过 Dockerfile 编写 linux 命令行工具

    测试 linux 压力的工具 一. 实际操作 1. 创建一个 ubuntu 的容器 docker run -it ubuntu 2. 安装 stress 工具 apt-get update & ...

  9. Android 开发命令行完全攻略

    作为命令行的爱好者,我想写这个主题已经有好一段时间了.除了显得很酷之外,命令行的使用能够提高我们的开发效率,因为相比通过鼠标点击一系列的菜单选项,使用键盘输入几个字符并点击 TAB 健显然会快很多. ...

随机推荐

  1. C# MySql分页存储过程的应用

    存储过程: 获取范围内的数据 DELIMITER $$ DROP PROCEDURE IF EXISTS `studb`.`GetRecordAsPage` $$ ),), ),)) BEGIN de ...

  2. 23.allegro中自动布线[原创]

    1. --- 方法①:选择网络自动布线 -- --- 已经步好: --- 方法②: ---- ---- 布线: --- 方法③: -- ----

  3. json格式的字符串转为json对象遇到特殊字符问题解决

    中午做后台发过来的json的时候转为对象,可是有几条数据一直出不来,检查发现json里包含了换行符,造成这种情况的原因可能是编辑部门在编辑的时候打的回车造成的 假设有这样一段json格式的字符串 va ...

  4. Java对ArrayList进行排序

    数字使用直接比较大小来排序,String的话,使用compare()方法进行排序. 测试代码: 1.对字符串对象排序 @Test public void test17() throws Excepti ...

  5. git中手动删除的文件如何在git中删除

    在日常开发中,我们可能或手动删除(delete键删除的)一些文件,然而我们本来应该是用git rm fileName命令删除的,但是现在我们手动删除了,那么要如何在git里面讲那些手动删除的文件删除呢 ...

  6. 双方都在线,qq总是离线发文件

    这是qq支持多地登录后出现的问题. 原因:1.当您传文件给对方,对方是多终端登录(或者开通移动在线功能)的情况下,为了保证对方一定能收到该文件,我们会智能的为用户切换到离线文件,对方会相应在所在的终端 ...

  7. open_table

    /* Open a table. SYNOPSIS open_table() thd Thread context. table_list Open first table in list. acti ...

  8. LeetCode Triangle 三角形(最短路)

    题意:给一个用序列堆成的三角形,第n层的元素个数为n,从顶往下,每个元素可以选择与自己最近的两个下层元素往下走,类似一棵二叉树,求最短路. [], [,4], [6,,7], [4,,8,3] 注意: ...

  9. nginx - conf.d vs sites-available

    自己理解: conf.d - 扩展配置文件,用户配置文件 sites-available - 配置 虚拟主机(nginx支持多个虚拟主机,sites-enabled(存放 软链接,指向sites-av ...

  10. 【Python】实践笔记

    为什么要在脚本中加入? import sys reload(sys) sys.setdefaultencoding('utf-8')