linux du 命令
Linux du(全称为 disk usage)命令用于查看目录或文件所占用的磁盘空间。
该命令会列出指定目录或文件的具体磁盘使用情况。
语法格式
du [-abcDhHklmsSx][-L ][-X ][--block-size][--exclude=][--max-depth=][--help][--version][目录或文件]
常用参数说明:
- -a 或 –all:显示目录中每个文件的具体大小。
- -b 或 –bytes:以字节(byte)为单位显示文件或目录的大小。
- -c 或 –total:除了显示各目录或文件的大小外,还会在最后显示总计大小。
- -D 或 –dereference-args:显示符号链接指向源文件的实际大小。
- -h 或 –human-readable:以 K、M、G 等易读单位显示大小。
- -H 或 –si:与 -h 类似,但单位换算按 1000 计算。
- -k 或 –kilobytes:以 1024 字节为单位进行显示。
- -l 或 –count-links:统计硬链接文件的大小,重复计算多次。
- -L 或 –dereference:显示所有符号链接对应源文件的大小。
- -m 或 –megabytes:以 MB(兆字节)为单位显示。
- -s 或 –summarize:仅显示目标目录或文件的总大小,不列出子目录详情。
- -S 或 –separate-dirs:显示目录大小时,不包含其子目录的大小。
- -x 或 –one-file-system:只统计同一文件系统下的目录,跨文件系统的目录跳过。
- -X 或 –exclude-from:排除指定的目录或文件不进行统计。
- –exclude=:忽略特定的目录或文件。
- –max-depth=:设定统计的最大目录层级,超出则忽略。
- –help:显示帮助信息。
- –version:输出命令版本信息。
使用示例
查看当前目录下各个文件和目录的磁盘使用情况:
# du 608 ./test6 308 ./test4 4 ./scf/lib 4 ./scf/service/deploy/product 4 ./scf/service/deploy/info 12 ./scf/service/deploy 16 ./scf/service 4 ./scf/doc 4 ./scf/bin 32 ./scf 8 ./test3 1288 .
上述结果显示了当前目录下各子目录和文件的大小,最后一行的 1288 表示整个目录的总大小。
查看单个文件的大小:
# du log2012.log 300 log2012.log
以更直观的方式查看 test 目录的使用情况:
# du -h test 608K test/test6 308K test/test4 4.0K test/scf/lib 4.0K test/scf/service/deploy/product 4.0K test/scf/service/deploy/info 12K test/scf/service/deploy 16K test/scf/service 4.0K test/scf/doc 4.0K test/scf/bin 32K test/scf 8.0K test/test3 1.3M test
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END