du命令是对文件和目录磁盘使用的空间的查看。

    (1)用法:

    用法:  du  [选项]  [文件]

    (2)功能:

    功能:  报告磁盘空间使用情况

    (3)选项参数:

1) -a  --all               显示对所有文件的统计,而不只是包含子目录。

2) -b  --bytes              输出以字节为单位的大小,替代缺省时1024字节的计数单位。

3) -h --human-readable          以K,M,G为单位,提高信息的可读性。

4) -s --summarize           对每个参数只显示总和

5) --max-depth=n           只输出命令行参数的小于等于第 n 层的目录的总计。 --max-depth=0的作用同于-s选项。

6) -m --megabytes            输出以兆字节的块为计数单位的大小(就是 1,048,576 字节)

7) -X file --exclude-from=file       除了从指定的文件中得到模式之外与 --exclude 一样。 模式以行的形式列出。如果指定的文件是'-',那么从标准输 入中读出模式。

8) -k --kilobytes              以KB(1024bytes)为单位输出

    (4)实例:

默认是1024个字节为单位

1)[root@localhost sunjimeng]# du Documents        显示目录或文件的空间使用情况

[root@localhost sunjimeng]# du Documents               //只显示目录
Documents/findDir/Dir/CDir
Documents/findDir/Dir
Documents/findDir
Documents/Pdir
Documents/NoPdir
Documents

显示文件的空间使用情况

[root@localhost sunjimeng]# du Documents/findDir/Dir/head_text
Documents/findDir/Dir/head_text     

2)[root@localhost sunjimeng]# du -a Documents      详细查看当前目录,子目录下的,所有文件和目录  

[root@localhost sunjimeng]# du -a Documents
Documents/findDir/Dir/head_text
Documents/findDir/Dir/less2
Documents/findDir/Dir/CDir
Documents/findDir/Dir/less1.gz
Documents/findDir/Dir
Documents/findDir
Documents/Pdir/find
Documents/Pdir/t3.txt
Documents/Pdir/vf
Documents/Pdir/uText
Documents/Pdir
Documents/NoPdir/find
Documents/NoPdir/t3.txt
Documents/NoPdir/vf
Documents/NoPdir/uText
Documents/NoPdir
Documents 

3)[root@localhost Document]# du          默认显示当前目录的文件夹的空间使用情况

[root@localhost Document]# du
./newDir
.
[root@localhost Document]# ll
总用量
-rw-r--r--. root users 5月 : all.txt
-rw-rw-r--. sunjimeng users 5月 : B.text3
-rw-rw-r--. sunjimeng users 5月 : C.text6
-rw-rw-r--. sunjimeng users 5月 : D.text
drwxr-xr-x. root users 5月 : newDir
-rw-r--r--. root users 5月 : t1.txt
-rw-r--r--. root users 5月 : t2.txt
[root@localhost Document]# cd ../
[root@localhost sunjimeng]# du Document
Document/newDir
Document

4)[root@localhost sunjimeng]# du -ah Documents      以易于阅读的方式显示

[root@localhost sunjimeng]# du -ah Documents
.0K Documents/findDir/Dir/head_text
.0K Documents/findDir/Dir/less2
Documents/findDir/Dir/CDir
.0K Documents/findDir/Dir/less1.gz
12K Documents/findDir/Dir
12K Documents/findDir
Documents/Pdir/find
.0K Documents/Pdir/t3.txt
.0K Documents/Pdir/vf
Documents/Pdir/uText
.0K Documents/Pdir
Documents/NoPdir/find
.0K Documents/NoPdir/t3.txt
.0K Documents/NoPdir/vf
Documents/NoPdir/uText
.0K Documents/NoPdir
28K Documents

5)[root@localhost sunjimeng]# du -hba Documents      以一个字节为单位显示

[root@localhost sunjimeng]# du -hba Documents
Documents/findDir/Dir/head_text
Documents/findDir/Dir/less2
Documents/findDir/Dir/CDir
Documents/findDir/Dir/less1.gz
Documents/findDir/Dir
Documents/findDir
Documents/Pdir/find
Documents/Pdir/t3.txt
Documents/Pdir/vf
Documents/Pdir/uText
Documents/Pdir
Documents/NoPdir/find
Documents/NoPdir/t3.txt
Documents/NoPdir/vf
Documents/NoPdir/uText
Documents/NoPdir
Documents

6)[root@localhost sunjimeng]# du -s *          只以总数显示子文件夹的空间使用情况

[root@localhost sunjimeng]# du -s *
Desktop
Document
Documents
Downloads
findTextDir
Music
Pictures
Public
Templates
Videos
[root@localhost sunjimeng]# du -s        //默认显示当前的文件夹sunjimeng

7)[root@localhost sunjimeng]# du -bh * |sort -n     根据目录的大小进行排序,包括目录的子目录

[root@localhost sunjimeng]# du -bh * |sort -n
.4K Documents
Desktop
Documents/findDir/Dir/CDir
Downloads
findTextDir
Music
Pictures
Public
Templates
Videos
Document/newDir
Documents/NoPdir
Documents/Pdir
Document
Documents/findDir/Dir
Documents/findDir

8)[root@localhost /]# du -ahm --max-depth=0      以M为单位显示文件夹的大小,并且可以指定显示的深度

[root@localhost /]# du -ahm --max-depth=0                    //深度为0表示只显示当前文件夹/的大小
du: 无法访问"./proc/4599/task/4599/fd/4": 没有那个文件或目录 //但必须将整个磁盘全部查询才知道结果
du: 无法访问"./proc/4599/task/4599/fdinfo/4": 没有那个文件或目录
du: 无法访问"./proc/4599/fd/4": 没有那个文件或目录
du: 无法访问"./proc/4599/fdinfo/4": 没有那个文件或目录
du: 无法访问"./run/user/1000/gvfs": 权限不够
.
[root@localhost /]# du -ahm --max-depth=
./boot
./dev
du: 无法访问"./proc/4670/task/4670/fd/4": 没有那个文件或目录
du: 无法访问"./proc/4670/task/4670/fdinfo/4": 没有那个文件或目录
du: 无法访问"./proc/4670/fd/4": 没有那个文件或目录
du: 无法访问"./proc/4670/fdinfo/4": 没有那个文件或目录
./proc
du: 无法访问"./run/user/1000/gvfs": 权限不够
./run
./sys
./etc
./root
./tmp
./var
./usr
./bin
./sbin
./lib
./lib64
./home
./media
./mnt
./opt
./srv
./touch_test
./touch_text
. //可知整个ext文件系统的空间使用情况是3540M左右

每天一个Linux命令(29)du命令的更多相关文章

  1. 每天一个linux命令(33)--du命令

    Linux  du命令也是查看使用空间的,但是与 df  命令不同的是 Linux du 命令是对文件和目录磁盘使用的空间的查看,还是和df 命令有一些区别的. 1.命令格式: du  [选项] [文 ...

  2. 每天一个linux命令:du 命令

    Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 1.命令格式: du [选项][文件] 2.命令功能 ...

  3. Linux命令之du命令

    du命令 显示文件或目录所占用的磁盘空间. 命令格式: du [option] 文件/目录 -h 输出文件系统分区使用的情况,例如:10KB,10MB,10GB等 -s 显示文件或整个目录的大小,默认 ...

  4. Linux centosVMware df命令、du命令、磁盘分区

    一.df命令 df(disk filesystem的简写)用于查看自己挂载磁盘的总容量.使用容量.剩余容量,可以不加任何参数,默认以KB为单位. [root@davery ~]# df文件系统 1K- ...

  5. linux命令:du 命令

    Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 1.命令格式: du [选项][文件] 2.命令功能 ...

  6. linux常用命令:du 命令

    Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 1.命令格式: du [选项] [文件|目录] 2. ...

  7. linux 命令格式、ls命令、du命令

    命令格式:命令 [-选项] [参数] ls -la /etc1.个别命令不遵循此格式2.当有多个选项时,可以写在一起,大多数顺序可以随意3.简化选项与完整选项 -a 等于 --all ls命令:ls ...

  8. df命令、du命令、磁盘分区 使用介绍

    第4周第1次课(4月9日) 课程内容:4.1 df命令4.2 du命令4.3/4.4 磁盘分区 4.1 df命令 汇报磁盘空间使用情况,linux磁盘挂载点是无法直接访问的. df 和 df -h区别 ...

  9. df命令,du命令,磁盘分区

    df 命令 功能:用来检查linux的文件系统的磁盘空间占用情况 1. df -h 2. 以innode节点数量显示磁盘空间占用情况 df -ih 3. 列出文件系统类型 df -Th du 命令 功 ...

  10. 【转发】du命令 实现Linux 某个文件夹下的文件按大小排序

    1. df -lh 2. du -s /usr/* | sort -rn这是按字节排序 3. du -sh /usr/* | sort -rn这是按兆(M)来排序 4.选出排在前面的10个du -s ...

随机推荐

  1. 关于清理 mac 其他文件的的方法

    mac 用于开发使用时间长硬盘会越来越小,速度越来越慢的, 亦是花了几分钟研究怎么清理系统的缓存, 方法: 1,到 https://www.omnigroup.com/more/ 安装 OmniDis ...

  2. 1 android 人脸识别

    1 https://www.google.com.hk/search?newwindow=1&safe=strict&q=android+%E5%9B%BE%E7%89%87%E4%B ...

  3. 在Java中怎样高效的推断数组中是否包括某个元素

    来自 http://www.hollischuang.com/archives/1269? 怎样检查一个数组(无序)是否包括一个特定的值?这是一个在Java中经经常使用到的并且非常实用的操作.同一时候 ...

  4. 深入浅出MySQL事务处理和锁机制

    1.      事务处理和并发性 1.1.        基础知识和相关概念 1 )全部的表类型都可以使用锁,但是只有 InnoDB 和 BDB 才有内置的事务功能. 2 )使用 begin 开始事务 ...

  5. 使用SpannableString实现一个load小动画

    依然是github开源项目:WaitingDots 这个项目代码不多,实现的非常easy.可是非常有意思由于动画的基本元素不是画出来的,而是使用了spannableString来实现. DotsTex ...

  6. Objective-C 的动态提示和技巧

    过去的几年中涌现了大量的Objective-C开发者.有些是从动态语言转过来的,比如Ruby或Python,有些是从强类型语言转过来的,如Java或C#,当然也有直接以Objective-C作为入门语 ...

  7. mysql使用存储过程制造测试数据

    DELIMITER $$ DROP PROCEDURE IF EXISTS message_insert_procedure; CREATE PROCEDURE `test`.`message_ins ...

  8. 细细品味大数据--初识hadoop

    初识hadoop 前言 之前在学校的时候一直就想学习大数据方面的技术,包括hadoop和机器学习啊什么的,但是归根结底就是因为自己太懒了,导致没有坚持多长时间,加上一直为offer做准备,所以当时重心 ...

  9. Live555 中的客户端动态库.so的调用方式之一 程序中调用

    1.  打开动态链接库:    #include <dlfcn.h>    void *dlopen(const char *filename, int flag);    该函数返回操作 ...

  10. Esper 20章 优化

    20 优化esper为了处理高速的生成力已经高度优化,并且接收事件和输出结果低延迟.esper还可以进一步最大化可测使用在 软实时和硬实时JVM 上. 本章描述了最好的优化练习,而且解释了怎么去评价e ...