常用鏈接

          統計

          最新評論

          DU和DF(轉)

           
          這個文檔能給你一個滿意的答復:) 
          Document Id: 26928Synopsis: du and df Differences (originally published 8/91) 
          Update date: 2001-05-13Description: du and df Differences 
          -- --- -- ----------- 

          This article explains how reporting disk usage du and reporting free disk space 
          on file systems df may show different numbers. 

          du 
          -- 

          The du user command gives the number of kilobytes contained in all files and, 
          recursively, directories within each specified directory or file (filename). 
          If filename is missing, `.' (the current directory) is used.  A file which 
          has multiple links to it is only counted once. 

          EXAMPLE: 

            system % du 

            5    ./jokes 
            33   ./squash 
            44   ./tech.papers/lpr.document 
            217  ./tech.papers/new.manager 
            401  ./tech.papers 
            144  ./memos 
            80   ./letters 
            388  ./window 
            93   ./messages 
            15   ./useful.news 
            1211 . 

          Note that the last number, 1211 is the grand total (in kilobytes) for the 
          directory. 

          df 
          -- 

          The df user command displays the following information: 

            amount of disk space occupied by currently mounted file systems 
            the amount of used and available space 
            how much of the file system's total capacity has been used 

          Used without arguments, df reports on all mounted file systems. 

          EXAMPLE: 

            system % df 

            Filesystem  kbytes  used  avail  capacity  Mounted on 
            /dev/ip0a    7445    4714 1986   70%       / 
            /dev/ip0g   42277   35291 2758   93%       /usr 

          Note: used plus avail is less than the amount of space in the file system 
          (kilobytes) because the system reserves a fraction of the space in the file 
          system to allow its allocation routines to work well.  The amount reserved is 
          typically about 10%.  (This may be adjusted using the tunefs command.  Refer to 
          the man pages on tunefs(8) for more information.)  When all the space on a file 
          system, except for this reserve, is in use, only the super-user can allocate 
          new files and data blocks to existing files.  This, however, may cause the file 
          system to be over allocated.  When a file system is over allocated in this way, 
          df may report that the file system is more than 100% utilized. 

          If arguments to df are disk partitions (for example, /dev/ip0as or path names), 
          df produces a report on the file system containing the named file.  Thus, df 
          shows the amount of space on the file system containing the current directory. 

          Problem Definition 
          ------- ---------- 

          This section gives the technical explanation of why du and df sometimes report 
          different totals of disk space usage. 

          When a program that is running in the background writes to a file while the 
          process is running, the file to which this process is writing is deleted. 
          Running df and du shows a discrepancy in the amount of disk space usage.  The 
          df command shows a higher value. 

          Explanation Summary 
          ----------- ------- 

          When you open a file, you get a pointer.  Subsequent writes to this file 
          references this file pointer.  The write call does not check to see if the file 
          is there or not.  It just writes to the specified number of characters starting 
          at a predetermined location.  Regardless of whether the file exist or not, disk 
          blocks are used by the write operation. 

          The df command reports the number of disk blocks used while du goes through the 
          file structure and and reports the number of blocks used by each directory.  As 
          far as du is concerned, the file used by the process does not exist, so it does 
          not report blocks used by this phantom file.  But df keeps track of disk blocks 
          used, and it reports the blocks used by this phantom file.
           du和df命令都被用于獲得文件系統大小的信息:df用于報告文件系統的總塊數及剩余塊數,du -s /<filesystem>用于報告文件系統使用的塊數。但是,我們可以發現從df命令算出的文件系統使用塊數的值與通過du命令得出的值是不一致的。如下例:
            # du -s /tmp 返回如下值:
            ---12920 /tmp
            而 df /tmp返回如下值:
            Filesystem --512-blocks-- Free --%Used --Iused-- %Iused --Mounted on
            /dev/hd3 --------57344 --42208--- 26% ----391 ------4% --/tmp

            從上面的值我們可以算出<total from df> - <Free from df> = <used block count>: 57344 - 42208 = 15136. 而15136大于12920。該值差異的存在是由于du與df命令實施上的不同: du -s命令通過將指定文件系統中所有的目錄、符號鏈接和文件使用的塊數累加得到該文件系統使用的總塊數;而df命令通過查看文件系統磁盤塊分配圖得出總塊數與剩余塊數。

            文件系統分配其中的一些磁盤塊用來記錄它自身的一些數據,如i節點,磁盤分布圖,間接塊,超級塊等。這些數據對大多數用戶級的程序來說是不可見的,通常稱為Meta Data。

            du命令是用戶級的程序,它不考慮Meta Data,而df命令則查看文件系統的磁盤分配圖并考慮Meta Data。df命令獲得真正的文件系統數據,而du命令只查看文件系統的部分情況。例如,一個frag=4096 并且 nbpi=4096的空的大小為4MB的日志文件系統中Meta Data的分配情況如下:

            1 4k block for the LVM

            2 4k super blocks

            2 4k blocks for disk maps

            2 4k blocks for inode maps

            2 4k blocks for .indirect

            32 4k blocks for inodes

            -------------------------

            41 4k blocks for meta data on an empty 4MB file system

            對于AIX 4.X版本:

            執行 du /foo返回的結果如下:

            ----8 -------/foo/lost+found

            ----16 ------/foo

            要使du命令輸出的結果與df命令輸出的結果匹配,我們必須要加上Meta Data。首先,將41個4k的塊轉換為以512字節為單位的值:

            41 * 8 = 328

            328(meta data) + 16(from du) = 344

            所以有344個以512字節為單位的塊分配給了這個空的文件系統。

            而使用 df /foo命令我們可以得到下面的結果:

            Filesystem --512-blocks --Free --%Used --Iused---%Iused --Mounted on

            /dev/lv01 ------8192 -----7848 -----5% -----16 -----2% ----/foo

            從中我們可以得到該文件系統使用的塊數:8192(total blocks) - 7848(free blocks) = 344。該值與上面得出的值一致。

            上面的換算方法對于空的文件系統很容易實現,但是對于非空的文件系統,由于Meta Data中文件間接塊的大小不定,因此較難實現。所以我們不需要查看du 與 df返回的值的匹配關系,而只需要了解du -s命令返回的值反映了分配給文件及目錄的磁盤塊數,而df命令則反映了文件系統的實際分配情況。df命令反映的實際情況包含了用戶數據(文件及目錄)和Meta Data。

            另一個表現出du與df命令不同之處的例子如下:

            如果用戶刪除了一個正在運行的應用所打開的某個目錄下的文件,則du命令返回的值顯示出減去了該文件后的目錄的大小。但df命令并不顯示減去該文件后的大小。直到該運行的應用關閉了這個打開的文件,df返回的值才顯示出減去了該文件后的文件系統的使用情況。

            列出一個目錄占用的空間

            1.

            du或du -s或du -k

            du -S | sort -n 可以迅速發現那個目錄是最大的。

            2.

            用df可以看到已安裝的文件系統的空間大小及剩余空間大小。

            3.

            quota -v查看用戶的磁盤空間信息,如果你用quota限制了用戶空間大小的話。

          posted on 2010-08-26 16:27 九寶 閱讀(154) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 定结县| 青川县| 天水市| 阿合奇县| 庄浪县| 东莞市| 凤阳县| 弥勒县| 鱼台县| 阆中市| 嘉义市| 壶关县| 张家界市| 昆山市| 罗源县| 泸州市| 沐川县| 罗江县| 高要市| 公安县| 那坡县| 珠海市| 霞浦县| 闻喜县| 松潘县| 汉川市| 乌拉特前旗| 潍坊市| 白银市| 开化县| 峨山| 巢湖市| 松桃| 利津县| 酒泉市| 乌海市| 新建县| 象山县| 宜章县| 内江市| 南宁市|