Linux查看磁碟空間的好方法

來源:互聯網
上載者:User

 

一、df 命令
df 是來自於coreutils 軟體包,系統安裝時,就內建的;我們通過這個命令可以查看磁碟的使用方式以及檔案系統被掛載的位置;舉例:

[root@localhost beinan]# df -lh
Filesystem 容量 已用 可用 已用% 掛載點
/dev/hda8 11G 6.0G 4.4G 58% /
/dev/shm 236M 0 236M 0% /dev/shm
/dev/sda1 56G 22G 35G 39% /mnt/sda1
我們從中可以看到,系統安裝在/dev/hda8 ;還有一個56G的磁碟分割/dev/sda1掛載在 /mnt/sda1中;
其它的參數請參考 man df

二、fdsik

fdisk 是一款強大的磁碟操作工具,來自util-linux軟體包,我們在這裡只說他如何查看磁碟分割表及分區結構;參數 -l ,通過-l 參數,能獲得機器中所有的硬碟的分區情況;

[root@localhost beinan]# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
55 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 765 6144831 7 HPFS/NTFS
/dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)
/dev/hda3 2806 7751 39728745 5 Extended
/dev/hda5 2806 3825 8193118+ 83 Linux
/dev/hda6 3826 5100 10241406 83 Linux
/dev/hda7 5101 5198 787153+ 82 Linux swap / Solaris
/dev/hda8 5199 6657 11719386 83 Linux
/dev/hda9 6658 7751 8787523+ 83 Linux

在上面Blocks中,表示的是分區的大小,Blocks的單位是byte ,我們可以換算成M,比如第一個分區/dev/hda1的大小如果換算成M,應該是6144831/1024=6000M,也就是6G左右,其實沒有這麼 麻煩,粗略的看一下把小數點向前移動三位,就知道大約的體積有多大了;

System 表示的檔案系統,比如/dev/hda1 是NTFS格式的;/dev/hda2 表示是fat32格式的檔案系統;.

在此例中,我們要特別注意的是/dev/hda3分區,這是擴充分區;他下麵包含著邏輯分區,其實這個分區相當於一個容器;從屬於她的有 hda5,hda6,hda7,hda8,hda9 ;

我們還注意到一點,怎麼沒有hda4呢?為什麼hda4沒有包含在擴充分區?一個磁碟最多有四個主要磁碟分割; hda1-4算都是主要磁碟分割;hda4不可能包含在擴充分區裡,另外擴充分區也算主要磁碟分割;在本例中,沒有hda4這個分區,當然我們可以把其中的一個分區設 置為主要磁碟分割,只是我當時分區的時候沒有這麼做而已;

再仔細統計一下,我們看一看這個磁碟是不是還有空間?hda1+hda2+hda3=實際已經分區的體積,所以我們可以這樣算 hda1+hda2+hda3=6144831+16386300+39728745 = 62259876 (b),換算成M單位,小數點向前移三位,所以目前已經劃分好的分區大約佔用體積是62259.876(M),其實最精確的計算 62259876/1024=60800.67(M);而這個磁碟大小是80.0 GB (80026361856byte),其實實際大小也就是78150.744(M);通過我們一系列的計算,我們可以得出這個硬碟目前還有使用的空間;大
約還有18G未分區的空間;

fdisk -l 能列出機器中所有磁碟的個數,也能列出所有磁碟分割情況;比如:
[root@localhost beinan]# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 765 6144831 7 HPFS/NTFS
/dev/hda2 766 2805 16386300 c W95 FAT32 (LBA)
/dev/hda3 2806 7751 39728745 5 Extended
/dev/hda5 2806 3825 8193118+ 83 Linux
/dev/hda6 3826 5100 10241406 83 Linux
/dev/hda7 5101 5198 787153+ 82 Linux swap / Solaris
/dev/hda8 5199 6657 11719386 83 Linux
/dev/hda9 6658 7751 8787523+ 83 Linux
/dev/sda: 60.0 GB, 60011642880 bytes
64 heads, 32 sectors/track, 57231 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 57231 58604528 83 Linux
 
通過上面我們可以知道此機器有兩塊硬碟,我們也可以指定fdisk -l 來查看其中一個硬碟的分區情況;

[root@localhost beinan]# fdisk -l /dev/sda
Disk /dev/sda: 60.0 GB, 60011642880 bytes
64 heads, 32 sectors/track, 57231 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 57231 58604528 83 Linux

通過上面情況可以知道,在/dev/sda 這個磁碟中,只有一個分區;使用量差不多是百分百了;

我們還可以來查看 /dev/hda的

[root@localhost beinan]# fdisk -l /dev/hda

三、查看目前機器中的所有磁碟及分區情況:

[beinan@localhost ~]$ cat /proc/partitions
major minor #blocks name
3 0 78150744 hda
3 1 6144831 hda1
3 2 16386300 hda2
3 5 8193118 hda5
3 6 10241406 hda6
3 7 787153 hda7
3 8 11719386 hda8
3 9 8787523 hda9
8 0 58605120 sda
8 1 58604528 sda1 

轉自:http://hi.baidu.com/carbens/blog/item/85872f893cee99b70e24446a.html

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.