linux:du和df区别

文章目录

  • [1. 概述](#1. 概述)
  • [2. du 命令](#2. du 命令)
  • [2. df 命令](#2. df 命令)
  • [3. 区别总结](#3. 区别总结)

1. 概述

dudf 都是 Linux 系统中用于查看磁盘空间使用情况的命令,但它们的功能和用法有所不同。

2. du 命令

du 是 "disk usage" 的缩写,用于显示文件或目录的磁盘使用情况。du 命令用于查看指定文件或目录的磁盘空间使用情况,可以递归地查看目录下所有文件和子目录的大小。

详细用法查看这里

bash 复制代码
du [OPTION]... [FILE]...

常用OPTION

  • -h:以人类可读的格式显示磁盘使用量,如 KB、MB、GB 等。
  • -s:显示指定目录的总大小,而不显示其子目录的大小。
  • -c:显示总计磁盘使用量。
  • -a:显示所有文件和目录的大小,包括隐藏文件。
  • -k-m-g:以 KB、MB、GB 等单位显示磁盘使用量。

2. df 命令

df 是 "disk free" 的缩写,用于显示文件系统的磁盘空间使用情况。df 命令用于查看系统中所有挂载的文件系统的磁盘空间使用情况,包括每个文件系统的总大小、已用空间、可用空间以及文件系统类型等信息。

bash 复制代码
df [OPTION]... [FILE]...

[OPTION]:
  -a, --all             include pseudo, duplicate, inaccessible file systems
  -B, --block-size=SIZE  scale sizes by SIZE before printing them; e.g.,
                           '-BM' prints sizes in units of 1,048,576 bytes;
                           see SIZE format below
  -h, --human-readable  print sizes in powers of 1024 (e.g., 1023M)
  -H, --si              print sizes in powers of 1000 (e.g., 1.1G)
  -i, --inodes          list inode information instead of block usage
  -k                    like --block-size=1K
  -l, --local           limit listing to local file systems
      --no-sync         do not invoke sync before getting usage info (default)
      --output[=FIELD_LIST]  use the output format defined by FIELD_LIST,
                               or print all fields if FIELD_LIST is omitted.
  -P, --portability     use the POSIX output format
      --sync            invoke sync before getting usage info
      --total           elide all entries insignificant to available space,
                          and produce a grand total
  -t, --type=TYPE       limit listing to file systems of type TYPE
  -T, --print-type      print file system type
  -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
  -v                    (ignored)
      --help     display this help and exit
      --version  output version information and exit

常用OPTION

  • -h:以人类可读的格式显示磁盘空间信息,如 KB、MB、GB 等。
  • -T:显示文件系统类型。
  • -t:仅显示指定类型的文件系统,如 ext4、tmpfs 等。
  • -i:显示 inode 的使用情况。

3. 区别总结

dudf 是两个不同的命令,用于查看不同层次的磁盘空间使用情况。

  • du 用于查看指定文件或目录的磁盘使用情况,而 df 用于查看系统中所有挂载的文件系统的磁盘空间使用情况。
  • du 只显示指定文件或目录的大小,而 df 显示文件系统的总大小、已用空间、可用空间等信息。
  • du 是针对文件或目录的,而 df 是针对文件系统的。
相关推荐
薛定谔的算法15 小时前
phoneGPT:构建专业领域的检索增强型智能问答系统
前端·数据库·后端
Databend17 小时前
Databend 亮相 RustChinaConf 2025,分享基于 Rust 构建商业化数仓平台的探索
数据库
得物技术18 小时前
破解gh-ost变更导致MySQL表膨胀之谜|得物技术
数据库·后端·mysql
LH_R1 天前
OneTerm开源堡垒机实战(四):访问授权与安全管控
运维·后端·安全
用户31187945592181 天前
Kylin Linux 10 安装 glib2-devel-2.62.5-7.ky10.x86_64.rpm 方法(附安装包)
linux
Raymond运维1 天前
MariaDB源码编译安装(二)
运维·数据库·mariadb
沢田纲吉1 天前
🗄️ MySQL 表操作全面指南
数据库·后端·mysql
涛啊涛1 天前
Centos7非LVM根分区容量不足后扩容,对调硬盘挂载/
linux·磁盘管理
RestCloud2 天前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud2 天前
为什么说零代码 ETL 是未来趋势?
数据库·api