linux空间管理,教你玩转Linux—磁盘管理
導(dǎo)讀
Linux磁盤管理好壞直接關(guān)系到整個系統(tǒng)的性能問題,Linux磁盤管理常用三個命令為df、du和fdisk。
df
df命令參數(shù)功能:檢查文件系統(tǒng)的磁盤空間占用情況。可以利用該命令來獲取硬盤被占用了多少空間,目前還剩下多少空間等信息。
語法:
df [-ahikHTm] [目錄或文件名]
選項與參數(shù):
-a :列出所有的文件系統(tǒng),包括系統(tǒng)特有的 /proc 等文件系統(tǒng);
-k :以 KBytes 的容量顯示各文件系統(tǒng);
-m :以 MBytes 的容量顯示各文件系統(tǒng);
-h :以人們較易閱讀的 GBytes, MBytes, KBytes 等格式自行顯示;
-H :以 M=1000K 取代 M=1024K 的進(jìn)位方式;
-T :顯示文件系統(tǒng)類型, 連同該 partition 的 filesystem 名稱 (例如 ext3) 也列出;
-i :不用硬盤容量,而以 inode 的數(shù)量來顯示
實例 1
將系統(tǒng)內(nèi)所有的文件系統(tǒng)列出來!
[root@www ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hdc2 9920624 3823112 5585444 41% /
/dev/hdc3 4956316 141376 4559108 4% /home
/dev/hdc1 101086 11126 84741 12% /boot
tmpfs 371332 0 371332 0% /dev/shm
在 Linux 底下如果 df 沒有加任何選項,那么默認(rèn)會將系統(tǒng)內(nèi)所有的 (不含特殊內(nèi)存內(nèi)的文件系統(tǒng)與 swap) 都以 1 Kbytes 的容量來列出來!
實例 2
將容量結(jié)果以易讀的容量格式顯示出來
[root@www ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hdc2 9.5G 3.7G 5.4G 41% /
/dev/hdc3 4.8G 139M 4.4G 4% /home
/dev/hdc1 99M 11M 83M 12% /boot
tmpfs 363M 0 363M 0% /dev/shm
實例 3
將系統(tǒng)內(nèi)的所有特殊文件格式及名稱都列出來
[root@www ~]# df -aT
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/hdc2 ext3 9920624 3823112 5585444 41% /
proc proc 0 0 0 - /proc
sysfs sysfs 0 0 0 - /sys
devpts devpts 0 0 0 - /dev/pts
/dev/hdc3 ext3 4956316 141376 4559108 4% /home
/dev/hdc1 ext3 101086 11126 84741 12% /boot
tmpfs tmpfs 371332 0 371332 0% /dev/shm
none binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_misc
sunrpc rpc_pipefs 0 0 0 - /var/lib/nfs/rpc_pipefs
實例 4
將 /etc 底下的可用的磁盤容量以易讀的容量格式顯示
[root@www ~]# df -h /etc
Filesystem Size Used Avail Use% Mounted on
/dev/hdc2 9.5G 3.7G 5.4G 41% /
du
Linux du命令也是查看使用空間的,但是與df命令不同的是Linux du命令是對文件和目錄磁盤使用的空間的查看,還是和df命令有一些區(qū)別的,這里介紹Linux du命令。
語法:
du [-ahskm] 文件或目錄名稱
選項與參數(shù):
-a :列出所有的文件與目錄容量,因為默認(rèn)僅統(tǒng)計目錄底下的文件量而已。
-h :以人們較易讀的容量格式 (G/M) 顯示;
-s :列出總量而已,而不列出每個各別的目錄占用容量;
-S :不包括子目錄下的總計,與 -s 有點差別。
-k :以 KBytes 列出容量顯示;
-m :以 MBytes 列出容量顯示;
實例 1
只列出當(dāng)前目錄下的所有文件夾容量(包括隱藏文件夾):
[root@www ~]# du
8 ./test4 < ==每個目錄都會列出來
8 ./test2
....中間省略....
12 ./.gconfd <==包括隱藏文件的目錄
220 . <==這個目錄(.)所占用的總量
直接輸入 du 沒有加任何選項時,則 du 會分析當(dāng)前所在目錄的文件與目錄所占用的硬盤空間。
實例 2
將文件的容量也列出來
[root@www ~]# du -a
12 ./install.log.syslog < ==有文件的列表了
8 ./.bash_logout
8 ./test4
8 ./test2
....中間省略....
12 ./.gconfd
220 .
實例 3
檢查根目錄底下每個目錄所占用的容量
[root@www ~]# du -sm /*
7 /bin
6 /boot
.....中間省略....
0 /proc
.....中間省略....
1 /tmp
3859 /usr < ==系統(tǒng)初期最大就是他了啦!
77 /var
通配符 * 來代表每個目錄。
與 df 不一樣的是,du 這個命令其實會直接到文件系統(tǒng)內(nèi)去搜尋所有的文件數(shù)據(jù)。
fdisk
fdisk 是 Linux 的磁盤分區(qū)表操作工具。
語法:
fdisk [-l] 裝置名稱
選項與參數(shù):
-l :輸出后面接的裝置所有的分區(qū)內(nèi)容。若僅有 fdisk -l 時, 則系統(tǒng)將會把整個系統(tǒng)內(nèi)能夠搜尋到的裝置的分區(qū)均列出來。
實例 1
列出所有分區(qū)信息
[root@AY120919111755c246621 tmp]# fdisk -l
Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/xvda1 * 1 2550 20480000 83 Linux
/dev/xvda2 2550 2611 490496 82 Linux swap / Solaris
Disk /dev/xvdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x56f40944
Device Boot Start End Blocks Id System
/dev/xvdb2 1 2610 20964793+ 83 Linux
實例 2
找出你系統(tǒng)中的根目錄所在磁盤,并查閱該硬盤內(nèi)的相關(guān)信息
[root@www ~]# df / < ==注意:重點在找出磁盤文件名而已
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hdc2 9920624 3823168 5585388 41% /
[root@www ~]# fdisk /dev/hdc <==仔細(xì)看,不要加上數(shù)字喔!
The number of cylinders for this disk is set to 5005.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): <==等待你的輸入!
輸入 m 后,就會看到底下這些命令介紹
Command (m for help): m < == 輸入 m 后,就會看到底下這些命令介紹
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition <==刪除一個partition
l list known partition types
m print this menu
n add a new partition <==新增一個partition
o create a new empty DOS partition table
p print the partition table <==在屏幕上顯示分割表
q quit without saving changes <==不儲存離開fdisk程序
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit <==將剛剛的動作寫入分割表
x extra functionality (experts only)
離開 fdisk 時按下 q,那么所有的動作都不會生效!相反的, 按下w就是動作生效的意思。
Command (m for help): p < == 這里可以輸出目前磁盤的狀態(tài)
Disk /dev/hdc: 41.1 GB, 41174138880 bytes <==這個磁盤的文件名與容量
255 heads, 63 sectors/track, 5005 cylinders <==磁頭、扇區(qū)與磁柱大小
Units = cylinders of 16065 * 512 = 8225280 bytes <==每個磁柱的大小
Device Boot Start End Blocks Id System
/dev/hdc1 * 1 13 104391 83 Linux
/dev/hdc2 14 1288 10241437+ 83 Linux
/dev/hdc3 1289 1925 5116702+ 83 Linux
/dev/hdc4 1926 5005 24740100 5 Extended
/dev/hdc5 1926 2052 1020096 82 Linux swap / Solaris
# 裝置文件名 啟動區(qū)否 開始磁柱 結(jié)束磁柱 1K大小容量 磁盤分區(qū)槽內(nèi)的系統(tǒng)
Command (m for help): q
想要不儲存離開嗎?按下 q 就對了!不要隨便按 w 啊!
使用 p 可以列出目前這顆磁盤的分割表信息,這個信息的上半部在顯示整體磁盤的狀態(tài)。
總結(jié)
以上是生活随笔為你收集整理的linux空间管理,教你玩转Linux—磁盘管理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 网卡绑定updelay,Li
- 下一篇: linux打开dc软件,Linux bc