zoukankan      html  css  js  c++  java
  • centos7目录统计之du命令

    CentOS下du查看计算目录大小的命令

     

    用法实例:

     

    [root@localhost local]# du -hs smgpdfd

    3.3G    smgpdfd

     

    [root@localhost local]# du -hs /usr/local/mysql/data/fdlfh

    42G     /usr/local/mysql/data/fdlfh

     

    查看整个硬盘的使用状况,硬盘空间

     

    [root@hskj ~]# df -hv

    文件系统              容量  已用 可用 已用% 挂载点

    /dev/sda3             9.7G  744M  8.5G   8% /

    /dev/sda6             199G  142G   48G  76% /usr

    /dev/sda2              48G  309M   45G   1% /home

    /dev/sda1              99M   12M   83M  12% /boot

    tmpfs                 2.0G     0  2.0G   0% /dev/shm

     

    介绍:

    du命令用于显示指定文件(夹)在磁盘中所占的空间信息。假如指定的文件参数实际上是一个目录,就要计算该目录下的所有文件。假如 没有提供文件参数,执行du命令,显示当前目录内的文件占用空间信息。

     

    语法:

     

    du [-abcDhHklmsSx] [-L <符号连接>] [--block-size] [--exclude=<目录或文件>] [--max-depth=<目录层数>] [目录或文件]

     

    选项介绍:

    -a: 显示目录中个别文件的大小;

    -b: 显示目录或文件大小时,以byte为单位;

    -c: 除了显示个别目录或文件的大小外,同时也显示所有目录或文件的总和;

    -D: 显示指定符号连接的源文件大小;

    -h: 以K,M,G为单位,提高信息的可读性;

    -H: 与-h参数相同,但是K,M,G是以1000为换算单位;

    -k: 以1024 bytes为单位;

    -l: 重复计算硬链接文件;

    -L<符号连接>: 显示选项中所指定符号链接(软链接)的源文件大小;

    -m: 以1MB为单位;

    -s: 显示总计大小;

    -S: 显示个别目录的大小时,并不含其子目录的大小;

    -x: 以一开始处理时的文件系统为准,若遇上其它不同的文件系统目录则略过;

    –exclude=<目录或文件>: 略过指定的目录或文件;

    –max-depth=<目录层数>: 超过指定层数的目录后,予以忽略;

     

    执行范例:

     

    view sourceprint?01>$ du#显示当前目录和所有子目录的大小, 单位为KB0212      ./dir1/sub10312      ./dir1/sub20456  ./dir20584  ./dir30648  ./dir4071464    .08$ du-sh #显示当前目录总大小,加-h提高信息的可读性091.5M    .10$ du–max-depth=1 -h #显示当前目录和第一层子目录的大小1124K     ./dir11256K ./dir21384K ./dir31448K ./dir4151.5M    .

     

    扩展阅读:

    相信长时间用linux的人一定遇到过整理磁盘的问题(由于磁盘空间将满)。想知道哪些文件夹的内容过大,删除一些大且无用文件。这时du命令会非常有用。在你用户目录下输入:

    du –max-depth=1 -h

    查看哪些文件夹的内容过大,然后进入那些文件夹,再不断的du –max-depth=1 -h,筛选出你要删除的文件,然后rm … , 大功告成!

     

    ——————————————————————————————————–

     

    Linux下查看目录大小的命令是du,从man中找到几个常用的参数就可以轻松的统计某个文件夹的容量.

     

    1.统计出目录的总大小,并以比较合适的单位表示

     

    -h, –human-readable

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

     

    -s, –summarize

    display only a total for each argument

     

    [blinux@localhost test]$ du -hs /boot

    5.7M    /boot

     

    2.当然了,你还可以让结果以单位b、k、m来表示

     

    [blinux@localhost test]$ du -bs /boot

    5746310 /boot

    [blinux@localhost test]$ du -ks /boot

    5772    /boot

    [blinux@localhost test]$ du -ms /boot

    6       /boot

     

    3.显示目录的总大小及目录树中各文件夹的大小,并以较好的单位表示

     

    [blinux@localhost test]$ du -h /boot

    308K    /boot/grub

    5.7M    /boot

  • 相关阅读:
    Median Value
    237. Delete Node in a Linked List
    206. Reverse Linked List
    160. Intersection of Two Linked Lists
    83. Remove Duplicates from Sorted List
    21. Merge Two Sorted Lists
    477. Total Hamming Distance
    421. Maximum XOR of Two Numbers in an Array
    397. Integer Replacement
    318. Maximum Product of Word Lengths
  • 原文地址:https://www.cnblogs.com/webnote/p/6065844.html
Copyright © 2011-2022 走看看