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 命令。
语法:
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
https://avg.163.com/topic/detail/11347521
https://avg.163.com/topic/detail/11347529
https://avg.163.com/topic/detail/11347520
https://avg.163.com/topic/detail/11347511
https://avg.163.com/topic/detail/11347539
https://avg.163.com/topic/detail/11347513
https://avg.163.com/topic/detail/11347613
https://avg.163.com/topic/detail/11347612
https://avg.163.com/topic/detail/11347611
https://avg.163.com/topic/detail/11347610
https://avg.163.com/topic/detail/11347609
https://avg.163.com/topic/detail/11347608
https://avg.163.com/topic/detail/11347606
https://avg.163.com/topic/detail/11347604
https://avg.163.com/topic/detail/11347605
https://avg.163.com/topic/detail/11347607
https://avg.163.com/topic/detail/11347603
https://avg.163.com/topic/detail/11347602
https://avg.163.com/topic/detail/11347601
https://avg.163.com/topic/detail/11347600
https://avg.163.com/topic/detail/11347598
https://avg.163.com/topic/detail/11347599
https://avg.163.com/topic/detail/11347597
https://avg.163.com/topic/detail/11347596
https://avg.163.com/topic/detail/11347595
https://avg.163.com/topic/detail/11347594
https://avg.163.com/topic/detail/11347593
https://avg.163.com/topic/detail/11347592
https://avg.163.com/topic/detail/11347591
https://avg.163.com/topic/detail/11347590
https://avg.163.com/topic/detail/11347589
https://avg.163.com/topic/detail/11347588
https://avg.163.com/topic/detail/11347587
https://avg.163.com/topic/detail/11347586
https://avg.163.com/topic/detail/11347584
https://avg.163.com/topic/detail/11347585
https://avg.163.com/topic/detail/11347583
https://avg.163.com/topic/detail/11347582
https://avg.163.com/topic/detail/11347581
https://avg.163.com/topic/detail/11347580
https://avg.163.com/topic/detail/11347579
https://avg.163.com/topic/detail/11347578
https://avg.163.com/topic/detail/11347577
https://avg.163.com/topic/detail/11347576
https://avg.163.com/topic/detail/11347575
https://avg.163.com/topic/detail/11347574
https://avg.163.com/topic/detail/11347573
https://avg.163.com/topic/detail/11347572
https://avg.163.com/topic/detail/11347571
https://avg.163.com/topic/detail/11347569
https://avg.163.com/topic/detail/11347567
https://avg.163.com/topic/detail/11347568
https://avg.163.com/topic/detail/11347566
https://avg.163.com/topic/detail/11347563
https://avg.163.com/topic/detail/11347565
https://avg.163.com/topic/detail/11347564
https://avg.163.com/topic/detail/11347562
https://avg.163.com/topic/detail/11347561
https://avg.163.com/topic/detail/11347559
https://avg.163.com/topic/detail/11347558
https://avg.163.com/topic/detail/11347557
https://avg.163.com/topic/detail/11347560
https://avg.163.com/topic/detail/11347555
https://avg.163.com/topic/detail/11347556
https://avg.163.com/topic/detail/11347554
https://avg.163.com/topic/detail/11347549
https://avg.163.com/topic/detail/11347553
https://avg.163.com/topic/detail/11347552
https://avg.163.com/topic/detail/11347544
https://avg.163.com/topic/detail/11347551
https://avg.163.com/topic/detail/11347547
https://avg.163.com/topic/detail/11347550
https://avg.163.com/topic/detail/11347548
https://avg.163.com/topic/detail/11347546
https://avg.163.com/topic/detail/11347545
https://avg.163.com/topic/detail/11347536
https://avg.163.com/topic/detail/11347543
https://avg.163.com/topic/detail/11347539
https://avg.163.com/topic/detail/11347540
https://avg.163.com/topic/detail/11347538
https://avg.163.com/topic/detail/11347537
https://avg.163.com/topic/detail/11347535
https://avg.163.com/topic/detail/11347534
https://avg.163.com/topic/detail/11347532
https://avg.163.com/topic/detail/11347531
https://avg.163.com/topic/detail/11347533
https://avg.163.com/topic/detail/11347530
https://avg.163.com/topic/detail/11347529
https://avg.163.com/topic/detail/11347527
https://avg.163.com/topic/detail/11347436
https://avg.163.com/topic/detail/11347526
https://avg.163.com/topic/detail/11347525
https://avg.163.com/topic/detail/11347521
https://avg.163.com/topic/detail/11347524
https://avg.163.com/topic/detail/11347523
https://avg.163.com/topic/detail/11347519
https://avg.163.com/topic/detail/11347517
https://avg.163.com/topic/detail/11347522
https://avg.163.com/topic/detail/11347520
https://avg.163.com/topic/detail/11347518
https://avg.163.com/topic/detail/11347515
https://avg.163.com/topic/detail/11347516
https://avg.163.com/topic/detail/11347513
https://avg.163.com/topic/detail/11347514
https://avg.163.com/topic/detail/11347511
https://avg.163.com/topic/detail/11347512
https://avg.163.com/topic/detail/11347510
https://avg.163.com/topic/detail/11347509
https://avg.163.com/topic/detail/11347508
https://avg.163.com/topic/detail/11347507
https://avg.163.com/topic/detail/11347506
https://avg.163.com/topic/detail/11347505
https://avg.163.com/topic/detail/11347504
https://avg.163.com/topic/detail/11347503
https://avg.163.com/topic/detail/11347502
https://avg.163.com/topic/detail/11347501
https://avg.163.com/topic/detail/11347500
https://avg.163.com/topic/detail/11347499
https://avg.163.com/topic/detail/11347496
https://avg.163.com/topic/detail/11347498
https://avg.163.com/topic/detail/11347497
https://avg.163.com/topic/detail/11347495
https://avg.163.com/topic/detail/11347493
https://avg.163.com/topic/detail/11347489
https://avg.163.com/topic/detail/11347494
https://avg.163.com/topic/detail/11347492
https://avg.163.com/topic/detail/11347490
https://avg.163.com/topic/detail/11347491
https://avg.163.com/topic/detail/11347488
https://avg.163.com/topic/detail/11347484
https://avg.163.com/topic/detail/11347486
https://avg.163.com/topic/detail/11347487
https://avg.163.com/topic/detail/11347485
https://avg.163.com/topic/detail/11347483
https://avg.163.com/topic/detail/11347482
https://avg.163.com/topic/detail/11347481
https://avg.163.com/topic/detail/11347479
https://avg.163.com/topic/detail/11347480
https://avg.163.com/topic/detail/11347478
https://avg.163.com/topic/detail/11347475
https://avg.163.com/topic/detail/11347476
https://avg.163.com/topic/detail/11347477
https://avg.163.com/topic/detail/11347474
https://avg.163.com/topic/detail/11347473
https://avg.163.com/topic/detail/11347472
https://avg.163.com/topic/detail/11347471
https://avg.163.com/topic/detail/11347470
https://avg.163.com/topic/detail/11347469
https://avg.163.com/topic/detail/11347468
https://avg.163.com/topic/detail/11347467
https://avg.163.com/topic/detail/11347466
https://avg.163.com/topic/detail/11347465
https://avg.163.com/topic/detail/11347462
https://avg.163.com/topic/detail/11347464
https://avg.163.com/topic/detail/11347463
https://avg.163.com/topic/detail/11347460
https://avg.163.com/topic/detail/11347461
https://avg.163.com/topic/detail/11347459
https://avg.163.com/topic/detail/11347458
https://avg.163.com/topic/detail/11347457
https://avg.163.com/topic/detail/11347456
https://avg.163.com/topic/detail/11347455
https://avg.163.com/topic/detail/11347454
https://avg.163.com/topic/detail/11347453
https://avg.163.com/topic/detail/11347452
https://avg.163.com/topic/detail/11347451
https://avg.163.com/topic/detail/11347448
https://avg.163.com/topic/detail/11347450
https://avg.163.com/topic/detail/11347449
https://avg.163.com/topic/detail/11347447
https://avg.163.com/topic/detail/11347446
https://avg.163.com/topic/detail/11347445
https://avg.163.com/topic/detail/11347444
https://avg.163.com/topic/detail/11347443
https://avg.163.com/topic/detail/11347442
https://avg.163.com/topic/detail/11347441
https://avg.163.com/topic/detail/11347440
https://avg.163.com/topic/detail/11347437
https://avg.163.com/topic/detail/11347439
https://avg.163.com/topic/detail/11347438
https://avg.163.com/topic/detail/11347436
https://avg.163.com/topic/detail/11347435
https://avg.163.com/topic/detail/11347433
https://avg.163.com/topic/detail/11347429
https://avg.163.com/topic/detail/11347430
https://avg.163.com/topic/detail/11347431
https://avg.163.com/topic/detail/11347432
https://avg.163.com/topic/detail/11347428
https://avg.163.com/topic/detail/11347427
https://avg.163.com/topic/detail/11347426
https://avg.163.com/topic/detail/11347425
https://avg.163.com/topic/detail/11347424
https://avg.163.com/topic/detail/11347423
https://avg.163.com/topic/detail/11347422
https://avg.163.com/topic/detail/11347421
https://avg.163.com/topic/detail/11347420
https://avg.163.com/topic/detail/11347419
https://avg.163.com/topic/detail/11347418
https://avg.163.com/topic/detail/11347413
https://avg.163.com/topic/detail/11347416
https://avg.163.com/topic/detail/11347414
https://avg.163.com/topic/detail/11347410
https://avg.163.com/topic/detail/11347411
https://avg.163.com/topic/detail/11347415
https://avg.163.com/topic/detail/11347417
https://avg.163.com/topic/detail/11347412
https://avg.163.com/topic/detail/11347409
https://avg.163.com/topic/detail/11347407
https://avg.163.com/topic/detail/11347406
https://avg.163.com/topic/detail/11347405
https://avg.163.com/topic/detail/11329428
https://avg.163.com/topic/detail/11329427
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 <== 这里可以输出目前磁盘的状态
Disk /dev/hdc: 41.1 GB, 41174138880 bytes <==这个磁盘的文件名与容量
255 heads, 63 sectors/track, 5005 cylinders <==磁头、扇区与磁柱大小
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
# 装置文件名 启动区否 开始磁柱 结束磁柱 1K大小容量 磁盘分区槽内的系统


