📘
Deuterium Wiki
  • Hello
  • Linux
    • cmd
      • du: 显式文件大小
      • seq: 生成序列
      • cat: 连接
      • cp: 复制
      • cd: 切换目录
      • mv: 移动
    • awk
      • 执行awk脚本
      • 删除空行
      • 个数统计
      • 文件的交集
      • 文件的差集
    • mysql
      • 删除重复数据
      • 导出数据不带标题
  • Reading
    • Novel
      • 《基督山伯爵》人物关系
    • Awesome CS Books
      • csapp-3e-homework-solution
        • 1. A Tour of Computer Systems
        • 2. Representing and Manipulating Information
          • 2.55 Compile and Run
          • 2.56 Another Try
          • 2.57 More show Procedures
          • 2.58 Check Little-Endian
          • 2.59 Bit Expressions
          • 2.60 Replace Byte
          • 2.61 More Bit Expressions
          • 2.62 Check Arithmetic Right Shift
          • 2.63 Logic & Arithmetic Right Shift
          • 2.64 Any Odd One
          • 2.65 Odd Ones
          • 2.66 Leftmost One
          • 2.67 Int Size is 32
          • 2.68 Lower One Mask
          • 2.69 Rotate Left
          • 2.70 Fits Bits
          • 2.71 Xbyte
          • 2.72 Copy Int
          • 2.73 Saturating Add
          • 2.74 Sub OK
          • 2.75 Unsigned High Prod
          • 2.76 calloc
          • 2.77 Multiple By Shifts
          • 2.78 Divide Power 2
          • 2.79 Mul3div4
          • 2.80 Three Fourths
          • 2.81 Generate Bits
          • 2.82 Signed and Unsigned
          • 2.83 Binary Floating Value
          • 2.84 Float Le
          • 2.85 Floating Point I
          • 2.86 Extend Precision
          • 2.87 Floating-Point II
          • 2.88 Floating-Point III
          • 2.89 Floating-Point IV
          • 2.90 fpwr2
          • 2.91 π
          • 2.92 Float Negate
          • 2.93 Float Absval
          • 2.94 Float Twice
          • 2.95 Float Half
          • 2.96 Float f2i
          • 2.97 Float i2f
        • 3. Machine-Level Representation of Programs
          • 3.58 Decode
          • 3.59 128-bit Multiply
          • 3.60 For Loop
          • 3.61 Conditional Data Transfer
          • 3.62 Switch I
          • 3.63 Switch II
          • 3.64 Multiple Dimension Array I
          • 3.65 Multiple Dimension Array II
          • 3.66 Multiple Dimension Array III
          • 3.67 Caller and Callee
          • 3.68 Alignment
          • 3.69 Struct
          • 3.70 Union
          • 3.71 fgets
          • 3.72 Variable-Size Stack
          • 3.73 Find Range I
          • 3.74 Find Range II
          • 3.75 Complex
      • tcpv1
        • ch01: Introduction
        • ch02: Link Layer
        • ch03: Internet Protocol
        • ch04: Address Resolutin Protocol
        • ch05: Reverse Address Resolution Protocol
        • ch06: Internet Control Message Protocol
        • ch07: Ping Program
        • ch08: Traceroute Program
        • ch09: IP Routing
        • ch10: Dynamic Routing Protocols
        • ch11: User Datagram Protocol
        • ch12: Broadcasting and Multicasting
        • ch13: Internet Group Management Protocol
        • ch14: The Domain Name System
        • ch15: Trivial File Transfer Protocol
        • ch16: Boostrap Protocol
        • ch17: Transmission Control Protocol
        • ch18: TCP Connection Establishment and Termination
        • ch 19: TCP Interactive Data Flow
        • ch20: TCP Bulk Data Flow
      • http
        • ch01: Overview of HTTP
        • ch02: URLs and Resources
        • ch03: HTTP Messages
        • ch04: Connection Management
        • ch05: Web Servers
        • ch06: Proxies
        • ch07: Caching
        • ch08: Integration Points
        • ch09: Web Robots
        • ch10: HTTP-NG
        • ch11: Client Identification and Cookies
        • ch12: Basic Authentication
        • ch13: Digest Authentication
        • ch14: Secure HTTP
        • ch15: Entities and Encodings
        • ch16: Internationalizated
        • ch17: Content Negotiation and Transcoding
        • ch18: Web Hosting
        • ch19: Publishing Systems
        • ch20: Redirections and Load Balancing
        • ch21: Logging and Usage Tracking
    • 提升认知
      • 《为什么需要生物学思维》
      • 《大话西方艺术史》
  • Mathematics
Powered by GitBook
On this page
  • 1. 命令格式
  • 2. 命令功能
  • 3. 命令参数
  • 4. 使用实例
  • 实例1:显式目录或文件所占空间
  • 实例2:显式指定文件所占空间
  • 实例3:查看指定目录的所占空间
  • 实例4:显式多个文件所占空间
  • 实例5:只显示总和
  • 实例6:方便阅读的格式
  • 实例7:文件和目录都显示
  • 实例8:显式指定几个文件,并统计总和
  • 实例9:按空间大小排序
  • 实例10:输出当前目录下各个子目录使用空间大小

Was this helpful?

  1. Linux
  2. cmd

du: 显式文件大小

Disk Usage

Linux du命令也是查看使用空间的,但是与df命令不同的是Linuxdu命令是对文件和目录磁盘使用空间的查看。

1. 命令格式

du [OPTION]... [FILE]...

2. 命令功能

显式每个文件和目录的磁盘使用空间,如果是目录,就递归显式。

3. 命令参数

参数

含义

-a, --all

显式所有文件的大小,而不仅仅是目录

--apparent-size

仅仅显式apparent大小,而不是磁盘占用空间。这个数据会比磁盘占用空间小一些

-B, --block-size=SIZE

使用SIZE指定的块大小输出

-b, --bytes

以byte为单位输出,等价于'--apparent-size --block-size=1'

-c, --tot

除了显式文件和目录的大小外,显式总和

-D, --dereference-args

dereference only symlinks that are listed on the command line

-H

等价于'--dereference-args (-D)'

-h, --human-readable

显式可读格式的大小(比如1K,234M,2G)

--si

类似于-h,但是以1000为转换单位

-k

等价于'--block-size=1K'

-l, --count-links

如果是硬链接就重复计算

-m

等价于'--block-size=1M'

-L, --dereference

dereference all symbolic links

-P, --no-dereference

don't follow any symbolic links (this is the default)

-S, --separate-dirs

显式大小时,不包含子目录的大小

-s, --summarize

仅显示总大小

-x, --one-file-system

仅以第一个文件系统为准,其他的略过

-X, --exclude-from=FILE

排除符合条件的文件

--exclude=PATTERN

排除符合条件的文件

--max-depth=N

递归计算目录大小时,最多递归到N层

--time

显式每个文件和目录的最后修改时间

4. 使用实例

实例1:显式目录或文件所占空间

du

结果:

0    ./search
0    ./article_process
0    ./subcenter
0    ./homepage
0    ./channel
0    ./jieba
65937776    ./toutiao_article_process
8280132    ./baijia_article_process
0    ./toutiao_channel
0    ./toutiao_jieba
0    ./toutiao_homepage
0    ./toutiao_search
0    ./douyin_channel
0    ./douyin_jieba
0    ./douyin_homepage
0    ./douyin_search
5858936    ./douyin_article_process
685904    ./douyin_topic_process
0    ./task_search
0    ./toutiao_task_search
74236    ./delete_cos_file
0    ./import_media_homepage
0    ./huoshan_channel
0    ./pipixia_channel
1108    ./bilibili_crawl
362720    ./douyin_bgm_process
129592    ./douyin_daren_process
12408    ./youtube_process
81342820    .

只显示当前目录下的子目录的大小和当前目录的总大小,最下面的是当前目录的总和。

实例2:显式指定文件所占空间

du info.log

结果:

3433284    info.log

实例3:查看指定目录的所占空间

du media_detect/

结果:

0    media_detect/search
0    media_detect/article_process
0    media_detect/subcenter
0    media_detect/homepage
0    media_detect/channel
0    media_detect/jieba
65937776    media_detect/toutiao_article_process
8280132    media_detect/baijia_article_process
0    media_detect/toutiao_channel
0    media_detect/toutiao_jieba
0    media_detect/toutiao_homepage
0    media_detect/toutiao_search
0    media_detect/douyin_channel
0    media_detect/douyin_jieba
0    media_detect/douyin_homepage
0    media_detect/douyin_search
5858936    media_detect/douyin_article_process
685904    media_detect/douyin_topic_process
0    media_detect/task_search
0    media_detect/toutiao_task_search
74236    media_detect/delete_cos_file
0    media_detect/import_media_homepage
0    media_detect/huoshan_channel
0    media_detect/pipixia_channel
1108    media_detect/bilibili_crawl
362720    media_detect/douyin_bgm_process
129592    media_detect/douyin_daren_process
12408    media_detect/youtube_process
81342820    media_detect/

实例4:显式多个文件所占空间

du info.log info.log.20190414 info.log.20190413

结果:

3433284    info.log
7011232    info.log.20190414
20199964    info.log.20190413

实例5:只显示总和

du -s
du -s toutiao_article_process/

结果:

65937780    .
65937780    toutiao_article_process/

实例6:方便阅读的格式

du -h info.log

结果:

3.3G    info.log

实例7:文件和目录都显示

du -ah

结果:

6.4G    ./toutiao_article_process/info_new_version.log
154M    ./toutiao_article_process/error.log.20190410
6.0G    ./toutiao_article_process/info.log.20190411
232M    ./toutiao_article_process/error.log.20190411
17G    ./toutiao_article_process/info.log.20190412
20G    ./toutiao_article_process/info.log.20190413
3.3G    ./toutiao_article_process/info.log
252M    ./toutiao_article_process/error.log.20190412
6.7G    ./toutiao_article_process/info.log.20190414
52K    ./toutiao_article_process/error.log.20190407
31M    ./toutiao_article_process/error_new_version.log
61M    ./toutiao_article_process/error.log
35M    ./toutiao_article_process/error.log.20190408
4.0K    ./toutiao_article_process/.info.log.swo
4.0K    ./toutiao_article_process/.info.log.swn
154M    ./toutiao_article_process/error.log.20190409
4.2G    ./toutiao_article_process/info.log.20190410
194M    ./toutiao_article_process/error.log.20190413
161M    ./toutiao_article_process/error.log.20190414
63G    ./toutiao_article_process

实例8:显式指定几个文件,并统计总和

du -c info.log info.log.20190414 info.log.20190413

结果:

3304388    info.log
7011232    info.log.20190414
20199964    info.log.20190413
30515584    total

实例9:按空间大小排序

du | sort -nr | more

结果:

81182196    .
65710208    ./toutiao_article_process
8369220    ./baijia_article_process
5836792    ./douyin_article_process
685904    ./douyin_topic_process
362720    ./douyin_bgm_process
129592    ./douyin_daren_process
74236    ./delete_cos_file
12408    ./youtube_process
1108    ./bilibili_crawl
0    ./toutiao_task_search
0    ./toutiao_search
0    ./toutiao_jieba
0    ./toutiao_homepage
0    ./toutiao_channel
0    ./task_search
0    ./subcenter
0    ./search
0    ./pipixia_channel
0    ./jieba
0    ./import_media_homepage
0    ./huoshan_channel
0    ./homepage
0    ./douyin_search
0    ./douyin_jieba
0    ./douyin_homepage
0    ./douyin_channel
0    ./channel
0    ./article_process

实例10:输出当前目录下各个子目录使用空间大小

du -h --max-depth=1

结果:

0    ./search
0    ./article_process
0    ./subcenter
0    ./homepage
0    ./channel
0    ./jieba
63G    ./toutiao_article_process
8.0G    ./baijia_article_process
0    ./toutiao_channel
0    ./toutiao_jieba
0    ./toutiao_homepage
0    ./toutiao_search
0    ./douyin_channel
0    ./douyin_jieba
0    ./douyin_homepage
0    ./douyin_search
5.6G    ./douyin_article_process
670M    ./douyin_topic_process
0    ./task_search
0    ./toutiao_task_search
73M    ./delete_cos_file
0    ./import_media_homepage
0    ./huoshan_channel
0    ./pipixia_channel
1.1M    ./bilibili_crawl
355M    ./douyin_bgm_process
127M    ./douyin_daren_process
13M    ./youtube_process
78G    .
PreviouscmdNextseq: 生成序列

Last updated 5 years ago

Was this helpful?