Linux 磁盘管理
Linux 磁盘管理好坏直接关系到整个系统的性能问题。
Linux 磁盘管理常用三个命令为 df、du 和 fdisk。
- df(英文全称:disk free):列出文件系统的整体磁盘使用量
- du(英文全称:disk used):检查磁盘空间使用量
- fdisk:用于磁盘分区
df
df命令参数功能:检查文件系统的磁盘空间占用情况。可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息。
语法:
df [-ahikHTm] [目录或文件名]
选项与参数:
-
-h:以人类可读的方式显示输出结果(例如,使用 KB、MB、GB 等单位)。
-
-T:显示文件系统的类型。
-
-t <文件系统类型>:只显示指定类型的文件系统。
-
-i:显示 inode 使用情况。
-
-H:该参数是 -h 的变体,但是使用 1000 字节作为基本单位而不是 1024 字节。这意味着它会以 SI(国际单位制)单位(例如 MB、GB)而不是二进制单位(例如 MiB、GiB)来显示磁盘使用情况。
-
-k:这个选项会以 KB 作为单位显示磁盘空间使用情况。
-
-a:该参数将显示所有的文件系统,包括虚拟文件系统,例如 proc、sysfs 等。如果没有使用该选项,默认情况下,df 命令不会显示虚拟文件系统。
实例 1
将系统内所有的文件系统列出来!
[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 没有加任何选项,那么默认会将系统内所有的 (不含特殊内存内的文件系统与 swap) 都以 1 Kbytes 的容量来列出来!
实例 2
将容量结果以易读的容量格式显示出来
[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
将系统内的所有特殊文件格式及名称都列出来
[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命令有一些区别的,这里介绍 Linux du 命令。
https://avg.163.com/topic/detail/9807901
https://avg.163.com/topic/detail/9807900
https://avg.163.com/topic/detail/9807899
https://avg.163.com/topic/detail/9807897
https://avg.163.com/topic/detail/9807898
https://avg.163.com/topic/detail/9807896
https://avg.163.com/topic/detail/9807895
https://avg.163.com/topic/detail/9807894
https://avg.163.com/topic/detail/9807892
https://avg.163.com/topic/detail/9807893
https://avg.163.com/topic/detail/9807890
https://avg.163.com/topic/detail/9807889
https://avg.163.com/topic/detail/9807888
https://avg.163.com/topic/detail/9807887
https://avg.163.com/topic/detail/9807886
https://avg.163.com/topic/detail/9807884
https://avg.163.com/topic/detail/9807885
https://avg.163.com/topic/detail/9807883
https://avg.163.com/topic/detail/9807865
https://avg.163.com/topic/detail/9807876
https://avg.163.com/topic/detail/9807711
https://avg.163.com/topic/detail/9807866
https://avg.163.com/topic/detail/9807862
https://avg.163.com/topic/detail/9807864
https://avg.163.com/topic/detail/9807863
https://avg.163.com/topic/detail/9807861
https://avg.163.com/topic/detail/9807860
https://avg.163.com/topic/detail/9807859
https://avg.163.com/topic/detail/9807858
https://avg.163.com/topic/detail/9807856
https://avg.163.com/topic/detail/9807857
https://avg.163.com/topic/detail/9807855
https://avg.163.com/topic/detail/9807854
https://avg.163.com/topic/detail/9807844
https://avg.163.com/topic/detail/9807837
https://avg.163.com/topic/detail/9807838
https://avg.163.com/topic/detail/9807836
https://avg.163.com/topic/detail/9807833
https://avg.163.com/topic/detail/9807834
https://avg.163.com/topic/detail/9807835
https://avg.163.com/topic/detail/9807832
https://avg.163.com/topic/detail/9807831
https://avg.163.com/topic/detail/9807830
https://avg.163.com/topic/detail/9807829
https://avg.163.com/topic/detail/9807828
https://avg.163.com/topic/detail/9807827
https://avg.163.com/topic/detail/9807826
https://avg.163.com/topic/detail/9807824
https://avg.163.com/topic/detail/9807823
https://avg.163.com/topic/detail/9807821
https://avg.163.com/topic/detail/9807818
https://avg.163.com/topic/detail/9807819
https://avg.163.com/topic/detail/9807806
https://avg.163.com/topic/detail/9807805
https://avg.163.com/topic/detail/9807804
https://avg.163.com/topic/detail/9807803
https://avg.163.com/topic/detail/9807802
https://avg.163.com/topic/detail/9807801
https://avg.163.com/topic/detail/9807800
https://avg.163.com/topic/detail/9807799
https://avg.163.com/topic/detail/9807795
https://avg.163.com/topic/detail/9807794
https://avg.163.com/topic/detail/9807791
https://avg.163.com/topic/detail/9807793
https://avg.163.com/topic/detail/9807787
https://avg.163.com/topic/detail/9807779
https://avg.163.com/topic/detail/9807777
https://avg.163.com/topic/detail/9807775
https://avg.163.com/topic/detail/9807774
https://avg.163.com/topic/detail/9807773
https://avg.163.com/topic/detail/9807772
https://avg.163.com/topic/detail/9807771
https://avg.163.com/topic/detail/9807770
https://avg.163.com/topic/detail/9807769
https://avg.163.com/topic/detail/9807768
https://avg.163.com/topic/detail/9807767
https://avg.163.com/topic/detail/9807766
https://avg.163.com/topic/detail/9807763
https://avg.163.com/topic/detail/9807765
https://avg.163.com/topic/detail/9807761
https://avg.163.com/topic/detail/9807762
https://avg.163.com/topic/detail/9807759
https://avg.163.com/topic/detail/9807760
https://avg.163.com/topic/detail/9807745
https://avg.163.com/topic/detail/9807744
https://avg.163.com/topic/detail/9807743
https://avg.163.com/topic/detail/9807742
https://avg.163.com/topic/detail/9807741
https://avg.163.com/topic/detail/9807740
https://avg.163.com/topic/detail/9807739
https://avg.163.com/topic/detail/9807738
https://avg.163.com/topic/detail/9807736
https://avg.163.com/topic/detail/9807735
https://avg.163.com/topic/detail/9807734
https://avg.163.com/topic/detail/9807733
https://avg.163.com/topic/detail/9807731
https://avg.163.com/topic/detail/9807732
https://avg.163.com/topic/detail/9807726
https://avg.163.com/topic/detail/9807725
https://avg.163.com/topic/detail/9807723
https://avg.163.com/topic/detail/9807724
https://avg.163.com/topic/detail/9807713
https://avg.163.com/topic/detail/9807712
https://avg.163.com/topic/detail/9807711
https://avg.163.com/topic/detail/9807710
https://avg.163.com/topic/detail/9807709
https://avg.163.com/topic/detail/9807708
https://avg.163.com/topic/detail/9807707
https://avg.163.com/topic/detail/9807706
https://avg.163.com/topic/detail/9807704
https://avg.163.com/topic/detail/9807702
https://avg.163.com/topic/detail/9807701
https://avg.163.com/topic/detail/9807695
https://avg.163.com/topic/detail/9807686
https://avg.163.com/topic/detail/9807692
https://avg.163.com/topic/detail/9807688
https://avg.163.com/topic/detail/9807489
https://avg.163.com/topic/detail/9807683
https://avg.163.com/topic/detail/9807682
https://avg.163.com/topic/detail/9807491
https://avg.163.com/topic/detail/9807681
https://avg.163.com/topic/detail/9807679
https://avg.163.com/topic/detail/9807678
https://avg.163.com/topic/detail/9807677
https://avg.163.com/topic/detail/9807676
https://avg.163.com/topic/detail/9807673
https://avg.163.com/topic/detail/9807675
https://avg.163.com/topic/detail/9807674
https://avg.163.com/topic/detail/9807672
https://avg.163.com/topic/detail/9807670
https://avg.163.com/topic/detail/9807665
https://avg.163.com/topic/detail/9807661
https://avg.163.com/topic/detail/9807656
https://avg.163.com/topic/detail/9807653
https://avg.163.com/topic/detail/9807652
https://avg.163.com/topic/detail/9807647
https://avg.163.com/topic/detail/9807650
https://avg.163.com/topic/detail/9807648
https://avg.163.com/topic/detail/9807649
https://avg.163.com/topic/detail/9807645
https://avg.163.com/topic/detail/9807646
https://avg.163.com/topic/detail/9807642
https://avg.163.com/topic/detail/9807640
https://avg.163.com/topic/detail/9807638
https://avg.163.com/topic/detail/9807637
https://avg.163.com/topic/detail/9807636
https://avg.163.com/topic/detail/9807632
https://avg.163.com/topic/detail/9807630
https://avg.163.com/topic/detail/9807623
https://avg.163.com/topic/detail/9807622
https://avg.163.com/topic/detail/9807621
https://avg.163.com/topic/detail/9807619
https://avg.163.com/topic/detail/9807620
https://avg.163.com/topic/detail/9807618
https://avg.163.com/topic/detail/9807617
https://avg.163.com/topic/detail/9807616
https://avg.163.com/topic/detail/9807615
https://avg.163.com/topic/detail/9807399
https://avg.163.com/topic/detail/9807614
https://avg.163.com/topic/detail/9807613
https://avg.163.com/topic/detail/9807612
https://avg.163.com/topic/detail/9807611
https://avg.163.com/topic/detail/9807610
https://avg.163.com/topic/detail/9807609
https://avg.163.com/topic/detail/9807608
https://avg.163.com/topic/detail/9807600
https://avg.163.com/topic/detail/9807598
https://avg.163.com/topic/detail/9807591
https://avg.163.com/topic/detail/9807588
https://avg.163.com/topic/detail/9807589
https://avg.163.com/topic/detail/9807587
https://avg.163.com/topic/detail/9807586
https://avg.163.com/topic/detail/9807585
https://avg.163.com/topic/detail/9807584
https://avg.163.com/topic/detail/9807562
https://avg.163.com/topic/detail/9807583
https://avg.163.com/topic/detail/9807582
https://avg.163.com/topic/detail/9807576
https://avg.163.com/topic/detail/9807573
https://avg.163.com/topic/detail/9807572
https://avg.163.com/topic/detail/9807547
https://avg.163.com/topic/detail/9807561
https://avg.163.com/topic/detail/9807560
https://avg.163.com/topic/detail/9807559
https://avg.163.com/topic/detail/9807557
https://avg.163.com/topic/detail/9807558
https://avg.163.com/topic/detail/9807554
https://avg.163.com/topic/detail/9807553
https://avg.163.com/topic/detail/9807551
https://avg.163.com/topic/detail/9807552
https://avg.163.com/topic/detail/9807550
https://avg.163.com/topic/detail/9807549
https://avg.163.com/topic/detail/9807540
https://avg.163.com/topic/detail/9807546
https://avg.163.com/topic/detail/9807547
https://avg.163.com/topic/detail/9807534
https://avg.163.com/topic/detail/9807543
https://avg.163.com/topic/detail/9807529
https://avg.163.com/topic/detail/9807528
https://avg.163.com/topic/detail/9807527
https://avg.163.com/topic/detail/9807526
https://avg.163.com/topic/detail/9807524
https://avg.163.com/topic/detail/9807523
https://avg.163.com/topic/detail/9807522
https://avg.163.com/topic/detail/9807521
https://avg.163.com/topic/detail/9807517
https://avg.163.com/topic/detail/9807519
https://avg.163.com/topic/detail/9807514
https://avg.163.com/topic/detail/9807518
https://avg.163.com/topic/detail/9807512
https://avg.163.com/topic/detail/9807507
https://avg.163.com/topic/detail/9807497
https://avg.163.com/topic/detail/9807496
https://avg.163.com/topic/detail/9807498
https://avg.163.com/topic/detail/9807495
https://avg.163.com/topic/detail/9807494
https://avg.163.com/topic/detail/9807493
https://avg.163.com/topic/detail/9807492
https://avg.163.com/topic/detail/9807491
https://avg.163.com/topic/detail/9807490
https://avg.163.com/topic/detail/9807487
https://avg.163.com/topic/detail/9807489
https://avg.163.com/topic/detail/9807485
https://avg.163.com/topic/detail/9807488
https://avg.163.com/topic/detail/9807484
https://avg.163.com/topic/detail/9807473
https://avg.163.com/topic/detail/9807483
https://avg.163.com/topic/detail/9807482
https://avg.163.com/topic/detail/9807480
https://avg.163.com/topic/detail/9807475
https://avg.163.com/topic/detail/9807479
https://avg.163.com/topic/detail/9807478
https://avg.163.com/topic/detail/9807476
https://avg.163.com/topic/detail/9807463
https://avg.163.com/topic/detail/9807461
https://avg.163.com/topic/detail/9807353
https://avg.163.com/topic/detail/9807459
https://avg.163.com/topic/detail/9807458
https://avg.163.com/topic/detail/9807457
https://avg.163.com/topic/detail/9807456
https://avg.163.com/topic/detail/9807455
https://avg.163.com/topic/detail/9807452
https://avg.163.com/topic/detail/9807451
https://avg.163.com/topic/detail/9807332
https://avg.163.com/topic/detail/9807445
https://avg.163.com/topic/detail/9807435
https://avg.163.com/topic/detail/9807434
https://avg.163.com/topic/detail/9807433
https://avg.163.com/topic/detail/9807432
https://avg.163.com/topic/detail/9807431
https://avg.163.com/topic/detail/9807430
https://avg.163.com/topic/detail/9807429
https://avg.163.com/topic/detail/9807427
https://avg.163.com/topic/detail/9807426
https://avg.163.com/topic/detail/9807425
https://avg.163.com/topic/detail/9807424
https://avg.163.com/topic/detail/9807423
https://avg.163.com/topic/detail/9807422
https://avg.163.com/topic/detail/9807421
https://avg.163.com/topic/detail/9807417
https://avg.163.com/topic/detail/9807396
https://avg.163.com/topic/detail/9807415
https://avg.163.com/topic/detail/9807414
https://avg.163.com/topic/detail/9807412
https://avg.163.com/topic/detail/9807405
https://avg.163.com/topic/detail/9807399
https://avg.163.com/topic/detail/9807398
https://avg.163.com/topic/detail/9807397
https://avg.163.com/topic/detail/9807395
https://avg.163.com/topic/detail/9807386
https://avg.163.com/topic/detail/9807393
https://avg.163.com/topic/detail/9807392
https://avg.163.com/topic/detail/9807391
https://avg.163.com/topic/detail/9807390
https://avg.163.com/topic/detail/9807388
https://avg.163.com/topic/detail/9807384
https://avg.163.com/topic/detail/9807377
https://avg.163.com/topic/detail/9807367
https://avg.163.com/topic/detail/9807369
https://avg.163.com/topic/detail/9807366
https://avg.163.com/topic/detail/9807365
https://avg.163.com/topic/detail/9807363
https://avg.163.com/topic/detail/9807362
https://avg.163.com/topic/detail/9807361
https://avg.163.com/topic/detail/9807359
https://avg.163.com/topic/detail/9807358
https://avg.163.com/topic/detail/9807355
https://avg.163.com/topic/detail/9807357
https://avg.163.com/topic/detail/9807356
https://avg.163.com/topic/detail/9807354
https://avg.163.com/topic/detail/9807353
https://avg.163.com/topic/detail/9807352
https://avg.163.com/topic/detail/9807349
https://avg.163.com/topic/detail/9807347
https://avg.163.com/topic/detail/9807343
https://avg.163.com/topic/detail/9807342
https://avg.163.com/topic/detail/9807334
https://avg.163.com/topic/detail/9807332
https://avg.163.com/topic/detail/9807331
https://avg.163.com/topic/detail/9807302
https://avg.163.com/topic/detail/9807300
https://avg.163.com/topic/detail/9807299
https://avg.163.com/topic/detail/9807297
https://avg.163.com/topic/detail/9807298
https://avg.163.com/topic/detail/9807296
https://avg.163.com/topic/detail/9807295
https://avg.163.com/topic/detail/9807294
https://avg.163.com/topic/detail/9807293
https://avg.163.com/topic/detail/9807291
https://avg.163.com/topic/detail/9807292
https://avg.163.com/topic/detail/9807290
语法:
du [-ahskm] 文件或目录名称
选项与参数:
- -a :列出所有的文件与目录容量,因为默认仅统计目录底下的文件量而已。
- -h :以人们较易读的容量格式 (G/M) 显示;
- -s :仅显示指定目录或文件的总大小,而不显示其子目录的大小。
- -S :包括子目录下的总计,与 -s 有点差别。
- -k :以 KBytes 列出容量显示;
- -m :以 MBytes 列出容量显示;
实例 1
只列出当前目录下的所有文件夹容量(包括隐藏文件夹):
[root@www ~]# du
8 ./test4 <==每个目录都会列出来
8 ./test2
….中间省略….
12 ./.gconfd <==包括隐藏文件的目录
220 . <==这个目录(.)所占用的总量
直接输入 du 没有加任何选项时,则 du 会分析当前所在目录里的子目录所占用的硬盘空间。
实例 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 <==系统初期最大就是他了啦!
77 /var
通配符 * 来代表每个目录。
与 df 不一样的是,du 这个命令其实会直接到文件系统内去搜寻所有的文件数据。
fdisk
fdisk 是 Linux 的磁盘分区表操作工具。
语法:
fdisk [-l] 装置名称
选项与参数:
- -l :输出后面接的装置所有的分区内容。若仅有 fdisk -l 时, 则系统将会把整个系统内能够搜寻到的装置的分区均列出来。
实例 1
列出所有分区信息
[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
找出你系统中的根目录所在磁盘,并查阅该硬盘内的相关信息
[root@www ~]# df / <==注意:重点在找出磁盘文件名而已
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hdc2 9920624 3823168 5585388 41% /
[root@www ~]# fdisk /dev/hdc <==仔细看,不要加上数字喔!
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 <== 这里可以输出目前磁盘的状态



