Linux查看磁盘的使用情况命令: df 和 du

时间:2022-03-09 16:48:33

Linux查看磁盘的使用情况命令: df  和 du

1.  df: (disk free, maybe)

功能:检查文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息。

语法:df [选项]

说明:df命令可显示所有文件系统对i节点和磁盘块的使用情况。

该命令各个选项的含义如下:

-a 显示所有文件系统的磁盘使用情况,包括0块(block)的文件系统,如/proc文件系统。

-k 以k字节为单位显示。

-i 显示i节点信息,而不是磁盘块。

-t 显示各指定类型的文件系统的磁盘空间使用情况。

-x 列出不是某一指定类型文件系统的磁盘空间使用情况(与t选项相反)。

-T 显示文件系统类型。

 

例1:列出各文件系统的磁盘空间使用情况。

$ df

Filesystem 1 K-blocks Used Available Use% Mounted on

/dev/hda2 1361587 1246406 44823 97% /


df命令的输出清单的说明如下:

第1列是代表文件系统对应的设备文件的路径名(一般是硬盘上的分区);

第2列给出分区包含的数据块(1024字节)的数目;

第3,4列分别表示已用的和可用的数据块数目。

用户也许会感到奇怪的是,第3,4列块数之和不等于第2列中的块数。

这是因为缺省的每个分区都留了少量空间供系统管理员使用。

即使遇到普通用户空间已满的情况,管理员仍能登录和留有解决问题所需的工作空间。

清单中Use% 列表示普通用户空间使用的百分比,即使这一数字达到100%,分区仍然留有系统管理员使用的空间。

最后,Mounted on列表示文件系统的挂载点。

 

例2:列出各文件系统的i节点使用情况。

$ df -ia

Filesystem Inodes IUsed IFree Iused% Mounted on

/dev/ hda2 352256 75043 277213 21% /

none 0 0 0 0% /proc

localhost:(pid221) 0 0 0 0% /net 

例3:列出文件系统的类型。

$ df -T

Filesystem Type 1K-blocks Used Available use% Mounted on

/dev/hda2 ext2 1361587 1246405 44824 97% /

例4. 最为实用的命令: df -ahT  #列出所有关在的文件系统的分区,文件的类型的使用情况, 以human-readable的格式。

df 命令选项的详细说明:

[root@embedded proc]# df --help
用法:df [选项]... [文件]...
Show information about the file system on which each FILE resides,
or all file systems by default.

长选项必须用的参数在使用短选项时也是必须的。
  -a, --all             include dummy file systems
  -B, --block-size=SIZE use SIZE-byte blocks
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
  -H, --si              likewise, but use powers of 1000 not 1024
  -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)
  -P, --portability     use the POSIX output format
      --sync            invoke sync before getting usage info
  -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     显示此帮助信息并退出
      --version  输出版本信息并退出

[大小]可以是以下的单位(单位前可加上整数):
kB 1000,K 1024,MB 1000000,M 1048576,还有 G、T、P、E、Z、Y。

请向 <bug-coreutils@gnu.org> 报告错误。
[root@embedded proc]#
 df的Linux Manual: 

[root@embedded proc]# man df | cat
DF(1)                            User Commands                           DF(1)



NAME
       df - report file system disk space usage

SYNOPSIS
       df [OPTION]... [FILE]...

DESCRIPTION
       This  manual  page  documents  the  GNU version of df.  df displays the
       amount of disk space available on the file system containing each  file
       name  argument.   If  no file name is given, the space available on all
       currently mounted file systems is shown.  Disk space  is  shown  in  1K
       blocks  by  default, unless the environment variable POSIXLY_CORRECT is
       set, in which case 512-byte blocks are used.

       If an argument is the absolute file name of a disk device node contain-
       ing  a  mounted  file system, df shows the space available on that file
       system rather than on the file system containing the device node (which
       is  always  the  root file system).  This version of df cannot show the
       space available on unmounted file systems, because  on  most  kinds  of
       systems  doing  so requires very nonportable intimate knowledge of file
       system structures.

OPTIONS
       Show information about the file system on which each FILE  resides,  or
       all file systems by default.

       Mandatory  arguments  to  long  options are mandatory for short options
       too.

       -a, --all
              include dummy file systems

       -B, --block-size=SIZE use SIZE-byte blocks

       -h, --human-readable
              print sizes in human readable format (e.g., 1K 234M 2G)

       -H, --si
              likewise, but use powers of 1000 not 1024

       -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)

       -P, --portability
              use the POSIX output format

       --sync invoke sync before getting usage info

       -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

       SIZE may be (or may be an integer optionally followed by) one  of  fol-
       lowing: kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T,
       P, E, Z, Y.

AUTHOR
       Written by Torbjorn Granlund, David MacKenzie, and Paul Eggert.

REPORTING BUGS
       Report bugs to <bug-coreutils@gnu.org>.

COPYRIGHT
       Copyright © 2006 Free Software Foundation, Inc.
       This is free software.  You may redistribute copies  of  it  under  the
       terms       of       the      GNU      General      Public      License
       <http://www.gnu.org/licenses/gpl.html>.  There is NO WARRANTY,  to  the
       extent permitted by law.

SEE ALSO
       The  full  documentation  for df is maintained as a Texinfo manual.  If
       the info and df programs are properly installed at your site, the  com-
       mand

              info df

       should give you access to the complete manual.



df 5.97                           March 2011                             DF(1)



2. du : (disk usage)

du的英文原义为“disk usage”,含义为显示磁盘空间的使用情况。  

功能:统计目录(或文件)所占磁盘空间的大小。  
语法:du [选项] [Names…]  
说明:该命令逐级进入指定目录的每一个子目录并显示该目录占用文件系统数据块(1024字节)的情况。
         若没有给出Names,则对当前目录进行统计。  


该命令的各个选项含义如下:  
-s 对每个Names参数只给出占用的数据块总数。  
-a 递归地显示指定目录中各文件及子孙目录中各文件占用的数据块数。

     若既不指定-s,也不指定-a,则只显示Names中的每一个目录及其中的各子目录所占的磁盘块数。  
-b 以字节为单位列出磁盘空间使用情况(系统缺省以k字节为单位)。  
-k 以1024字节为单位列出磁盘空间使用情况。  
-c 最后再加上一个总计(系统缺省设置)。  
-l 计算所有的文件大小,对硬链接文件,则计算多次。  
-x 跳过在不同文件系统上的目录不予统计。  
下面举例说明du命令的使用:  
例1:查看/mnt目录占用磁盘空间的情况。 
$ cd /mnt 
$ ls -lFR 
total 8
-rwxrwxrwx 2 root root ll0 Ju1 3l 00:33 aa*  
drwxr-xr-x 2 root root l024 Ju1 20 14:16 dev/
-rw-r--r-- 1 root root 6229 Aug 2 0l:39 s1ack
drwxrwxrwx 2 root root 1024 Aug 2 02:09 var/ 
1rwxrwxrwx 1 root root l0 Aug 2 0l:51 wei->/home/dfsa   
例2:列出各目录所占的磁盘空间,但不详细列出每个文件所占的空间。
$ du  
l ./dev
38 ./var  
48 .  
输出清单中的第一列是以块为单位计的磁盘空间容量,第二列列出目录中使用这些空间的目录名称。  
注意不带选项的du命令将从当前目录开始沿着目录结构向下工作直到列出所有目录的容量为止。
这可能是一个很长的清单,有时只需要一个总数。这时可在du命令中加-s选项来取得总数:  
$ du –s /mnt
/mnt  
例3:列出所有文件和目录所占的空间(使用a选项),而且以字节为单位(使用b选项)来计算大小。
$ du -ab  
8 ./dev/cdrom
l032 ./dev  
36064 ./var/rawrite. exe
37088 ./var
6229 ./s1ack
1l0 ./aa
l0 ./wei  
45493 .  


du 的使用选项:

[root@embedded proc]# du --help
用法:du [选项]... [文件]...
  或:du [选项]... --files0-from=F
总结每个<文件>的磁盘用量,目录则取总用量。

长选项必须用的参数在使用短选项时也是必须的。
  -a, --all             write counts for all files, not just directories
      --apparent-size   print apparent sizes, rather than disk usage; although
                          the apparent size is usually smaller, it may be
                          larger due to holes in (`sparse') files, internal
                          fragmentation, indirect blocks, and the like
  -B, --block-size=SIZE use SIZE-byte blocks
  -b, --bytes           equivalent to `--apparent-size --block-size=1'
  -c, --total           produce a grand total
  -D, --dereference-args  dereference FILEs that are symbolic links
      --files0-from=F   summarize disk usage of the NUL-terminated file
                          names specified in file F
  -H                    like --si, but also evokes a warning; will soon
                          change to be equivalent to --dereference-args (-D)
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
      --si              like -h, but use powers of 1000 not 1024
  -k                    like --block-size=1K
  -l, --count-links     count sizes many times if hard linked
  -m                    like --block-size=1M
  -L, --dereference     dereference all symbolic links
  -P, --no-dereference  don't follow any symbolic links (this is the default)
  -0, --null            end each output line with 0 byte rather than newline
  -S, --separate-dirs   do not include size of subdirectories
  -s, --summarize       display only a total for each argument
  -x, --one-file-system  skip directories on different file systems
  -X FILE, --exclude-from=FILE  Exclude files that match any pattern in FILE.
      --exclude=PATTERN Exclude files that match PATTERN.
      --max-depth=N     print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;  --max-depth=0 is the same as
                          --summarize
      --time            show time of the last modification of any file in the
                          directory, or any of its subdirectories
      --time=WORD       show time as WORD instead of modification time:
                          atime, access, use, ctime or status
      --time-style=STYLE show times using style STYLE:
                          full-iso, long-iso, iso, +FORMAT
                          FORMAT is interpreted like `date'
      --help     显示此帮助信息并退出
      --version  输出版本信息并退出

[大小]可以是以下的单位(单位前可加上整数):
kB 1000,K 1024,MB 1000000,M 1048576,还有 G、T、P、E、Z、Y。

请向 <bug-coreutils@gnu.org> 报告错误。
[root@embedded proc]#


du 的Linux Manual:

[root@embedded ~]# man du | cat
DU(1)                            User Commands                           DU(1)



NAME
       du - estimate file space usage

SYNOPSIS
       du [OPTION]... [FILE]...
       du [OPTION]... --files0-from=F

DESCRIPTION
       Summarize disk usage of each FILE, recursively for directories.

       Mandatory  arguments  to  long  options are mandatory for short options
       too.

       -a, --all
              write counts for all files, not just directories

       --apparent-size
              print apparent sizes,  rather  than  disk  usage;  although  the
              apparent  size is usually smaller, it may be larger due to holes
              in (‘sparse’) files, internal  fragmentation,  indirect  blocks,
              and the like

       -B, --block-size=SIZE use SIZE-byte blocks

       -b, --bytes
              equivalent to ‘--apparent-size --block-size=1’

       -c, --total
              produce a grand total

       -D, --dereference-args
              dereference FILEs that are symbolic links

       --files0-from=F
              summarize  disk usage of the NUL-terminated file names specified
              in file F

       -H     like --si, but also evokes a warning; will  soon  change  to  be
              equivalent to --dereference-args (-D)

       -h, --human-readable
              print sizes in human readable format (e.g., 1K 234M 2G)

       --si   like -h, but use powers of 1000 not 1024

       -k     like --block-size=1K

       -l, --count-links
              count sizes many times if hard linked

       -m     like --block-size=1M

       -L, --dereference
              dereference all symbolic links

       -P, --no-dereference
              don’t follow any symbolic links (this is the default)

       -0, --null
              end each output line with 0 byte rather than newline

       -S, --separate-dirs
              do not include size of subdirectories

       -s, --summarize
              display only a total for each argument

       -x, --one-file-system
              skip directories on different file systems

       -X FILE, --exclude-from=FILE
              Exclude files that match any pattern in FILE.

       --exclude=PATTERN Exclude files that match PATTERN.

       --max-depth=N
              print the total for a directory (or file, with --all) only if it
              is  N  or  fewer  levels  below  the  command   line   argument;
              --max-depth=0 is the same as --summarize

       --time show time of the last modification of any file in the directory,
              or any of its subdirectories

       --time=WORD
              show time as WORD instead of modification time:  atime,  access,
              use, ctime or status

       --time-style=STYLE show times using style STYLE:
              full-iso,  long-iso,  iso,  +FORMAT  FORMAT  is interpreted like
              ‘date’

       --help display this help and exit

       --version
              output version information and exit

       SIZE may be (or may be an integer optionally followed by) one  of  fol-
       lowing: kB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T,
       P, E, Z, Y.

PATTERNS
       PATTERN is a shell pattern (not a regular expression).  The  pattern  ?
       matches  any  one  character, whereas * matches any string (composed of
       zero, one or multiple characters).  For example,  *.o  will  match  any
       files whose names end in .o.  Therefore, the command

              du --exclude=’*.o’

       will skip all files and subdirectories ending in .o (including the file
       .o itself).

AUTHOR
       Written by Torbjorn Granlund, David MacKenzie,  Paul  Eggert,  and  Jim
       Meyering.

REPORTING BUGS
       Report bugs to <bug-coreutils@gnu.org>.

COPYRIGHT
       Copyright © 2006 Free Software Foundation, Inc.
       This  is  free  software.   You may redistribute copies of it under the
       terms      of      the      GNU      General       Public       License
       <http://www.gnu.org/licenses/gpl.html>.   There  is NO WARRANTY, to the
       extent permitted by law.

SEE ALSO
       The full documentation for du is maintained as a  Texinfo  manual.   If
       the  info and du programs are properly installed at your site, the com-
       mand

              info du

       should give you access to the complete manual.



du 5.97                           March 2011                             DU(1)