Linux 磁盘管理《自写篇》
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
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
https://avg.163.com/topic/detail/9807289
https://avg.163.com/topic/detail/9807288
https://avg.163.com/topic/detail/9807287
https://avg.163.com/topic/detail/9807286
https://avg.163.com/topic/detail/9807285
https://avg.163.com/topic/detail/9807284
https://avg.163.com/topic/detail/9807282
https://avg.163.com/topic/detail/9807283
https://avg.163.com/topic/detail/9807281
https://avg.163.com/topic/detail/9807280
https://avg.163.com/topic/detail/9807279
https://avg.163.com/topic/detail/9807278
https://avg.163.com/topic/detail/9807277
https://avg.163.com/topic/detail/9807275
https://avg.163.com/topic/detail/9807274
https://avg.163.com/topic/detail/9807273
https://avg.163.com/topic/detail/9807272
https://avg.163.com/topic/detail/9807271
https://avg.163.com/topic/detail/9807270
https://avg.163.com/topic/detail/9807260
https://avg.163.com/topic/detail/9807268
https://avg.163.com/topic/detail/9807267
https://avg.163.com/topic/detail/9807266
https://avg.163.com/topic/detail/9807265
https://avg.163.com/topic/detail/9807264
https://avg.163.com/topic/detail/9807263
https://avg.163.com/topic/detail/9807262
https://avg.163.com/topic/detail/9807261
https://avg.163.com/topic/detail/9807260
https://avg.163.com/topic/detail/9807259
https://avg.163.com/topic/detail/9807255
https://avg.163.com/topic/detail/9807257
https://avg.163.com/topic/detail/9807256
https://avg.163.com/topic/detail/9807254
https://avg.163.com/topic/detail/9807253
https://avg.163.com/topic/detail/9807251
https://avg.163.com/topic/detail/9807252
https://avg.163.com/topic/detail/9807250
https://avg.163.com/topic/detail/9807249
https://avg.163.com/topic/detail/9807248
https://avg.163.com/topic/detail/9807238
https://avg.163.com/topic/detail/9807247
https://avg.163.com/topic/detail/9807246
https://avg.163.com/topic/detail/9807245
https://avg.163.com/topic/detail/9807243
https://avg.163.com/topic/detail/9807242
https://avg.163.com/topic/detail/9807240
https://avg.163.com/topic/detail/9807239
https://avg.163.com/topic/detail/9807238
https://avg.163.com/topic/detail/9807237
https://avg.163.com/topic/detail/9807236
https://avg.163.com/topic/detail/9807235
https://avg.163.com/topic/detail/9807225
https://avg.163.com/topic/detail/9807234
https://avg.163.com/topic/detail/9807233
https://avg.163.com/topic/detail/9807232
https://avg.163.com/topic/detail/9807231
https://avg.163.com/topic/detail/9807230
https://avg.163.com/topic/detail/9807229
https://avg.163.com/topic/detail/9807228
https://avg.163.com/topic/detail/9807227
https://avg.163.com/topic/detail/9807226
https://avg.163.com/topic/detail/9807225
https://avg.163.com/topic/detail/9807223
https://avg.163.com/topic/detail/9807222
https://avg.163.com/topic/detail/9807221
https://avg.163.com/topic/detail/9807219
https://avg.163.com/topic/detail/9807218
https://avg.163.com/topic/detail/9807216
https://avg.163.com/topic/detail/9807215
https://avg.163.com/topic/detail/9807214
https://avg.163.com/topic/detail/9807213
https://avg.163.com/topic/detail/9807212
https://avg.163.com/topic/detail/9807211
https://avg.163.com/topic/detail/9807210
https://avg.163.com/topic/detail/9807199
https://avg.163.com/topic/detail/9807209
https://avg.163.com/topic/detail/9807208
https://avg.163.com/topic/detail/9807179
https://avg.163.com/topic/detail/9807207
https://avg.163.com/topic/detail/9807206
https://avg.163.com/topic/detail/9807205
https://avg.163.com/topic/detail/9807189
https://avg.163.com/topic/detail/9807187
https://avg.163.com/topic/detail/9807204
https://avg.163.com/topic/detail/9807203
https://avg.163.com/topic/detail/9807202
https://avg.163.com/topic/detail/9807201
https://avg.163.com/topic/detail/9807199
https://avg.163.com/topic/detail/9807198
https://avg.163.com/topic/detail/9807197
https://avg.163.com/topic/detail/9807179
https://avg.163.com/topic/detail/9807196
https://avg.163.com/topic/detail/9807195
https://avg.163.com/topic/detail/9807194
https://avg.163.com/topic/detail/9807193
https://avg.163.com/topic/detail/9807190
https://avg.163.com/topic/detail/9807189
https://avg.163.com/topic/detail/9807188
https://avg.163.com/topic/detail/9807187
https://avg.163.com/topic/detail/9807186
https://avg.163.com/topic/detail/9807185
https://avg.163.com/topic/detail/9807184
https://avg.163.com/topic/detail/9807181
https://avg.163.com/topic/detail/9807183
https://avg.163.com/topic/detail/9807182
https://avg.163.com/topic/detail/9807180
https://avg.163.com/topic/detail/9807179
https://avg.163.com/topic/detail/9807178
https://avg.163.com/topic/detail/9807177
https://avg.163.com/topic/detail/9807176
https://avg.163.com/topic/detail/9807175
https://avg.163.com/topic/detail/9807174
https://avg.163.com/topic/detail/9807173
https://avg.163.com/topic/detail/9807171
https://avg.163.com/topic/detail/9807172
https://avg.163.com/topic/detail/9807170
https://avg.163.com/topic/detail/9807169
https://avg.163.com/topic/detail/9807156
https://avg.163.com/topic/detail/9807168
https://avg.163.com/topic/detail/9807167
https://avg.163.com/topic/detail/9807166
https://avg.163.com/topic/detail/9807165
https://avg.163.com/topic/detail/9807163
https://avg.163.com/topic/detail/9807162
https://avg.163.com/topic/detail/9807161
https://avg.163.com/topic/detail/9807159
https://avg.163.com/topic/detail/9807158
https://avg.163.com/topic/detail/9807132
https://avg.163.com/topic/detail/9807157
https://avg.163.com/topic/detail/9807156
https://avg.163.com/topic/detail/9807155
https://avg.163.com/topic/detail/9807152
https://avg.163.com/topic/detail/9807152
https://avg.163.com/topic/detail/9807154
https://avg.163.com/topic/detail/9807151
https://avg.163.com/topic/detail/9807153
https://avg.163.com/topic/detail/9807152
https://avg.163.com/topic/detail/9807148
https://avg.163.com/topic/detail/9807147
https://avg.163.com/topic/detail/9807146
https://avg.163.com/topic/detail/9807145
https://avg.163.com/topic/detail/9807144
https://avg.163.com/topic/detail/9807143
https://avg.163.com/topic/detail/9807142
https://avg.163.com/topic/detail/9807141
https://avg.163.com/topic/detail/9807140
https://avg.163.com/topic/detail/9807138
https://avg.163.com/topic/detail/9807137
https://avg.163.com/topic/detail/9807135
https://avg.163.com/topic/detail/9807105
https://avg.163.com/topic/detail/9807133
https://avg.163.com/topic/detail/9807131
https://avg.163.com/topic/detail/9807128
https://avg.163.com/topic/detail/9807126
https://avg.163.com/topic/detail/9807121
https://avg.163.com/topic/detail/9807112
https://avg.163.com/topic/detail/9807111
https://avg.163.com/topic/detail/9807110
https://avg.163.com/topic/detail/9807109
https://avg.163.com/topic/detail/9807108
https://avg.163.com/topic/detail/9807107
https://avg.163.com/topic/detail/9807106
https://avg.163.com/topic/detail/9807105
https://avg.163.com/topic/detail/9807090
https://avg.163.com/topic/detail/9807051
https://avg.163.com/topic/detail/9807088
https://avg.163.com/topic/detail/9807089
https://avg.163.com/topic/detail/9807064
https://avg.163.com/topic/detail/9807087
https://avg.163.com/topic/detail/9807086
https://avg.163.com/topic/detail/9807085
https://avg.163.com/topic/detail/9807070
https://avg.163.com/topic/detail/9807069
https://avg.163.com/topic/detail/9807068
https://avg.163.com/topic/detail/9807066
https://avg.163.com/topic/detail/9807067
https://avg.163.com/topic/detail/9807065
https://avg.163.com/topic/detail/9807064
https://avg.163.com/topic/detail/9807061
https://avg.163.com/topic/detail/9807051
https://avg.163.com/topic/detail/9807047
https://avg.163.com/topic/detail/9807046
https://avg.163.com/topic/detail/9807045
https://avg.163.com/topic/detail/9807044
https://avg.163.com/topic/detail/9807043
https://avg.163.com/topic/detail/9806986
https://avg.163.com/topic/detail/9807040
https://avg.163.com/topic/detail/9807038
https://avg.163.com/topic/detail/9807039
https://avg.163.com/topic/detail/9807037
https://avg.163.com/topic/detail/9807036
https://avg.163.com/topic/detail/9807007
https://avg.163.com/topic/detail/9806986
https://avg.163.com/topic/detail/9806985
https://avg.163.com/topic/detail/9806975
https://avg.163.com/topic/detail/9806974
https://avg.163.com/topic/detail/9806973
https://avg.163.com/topic/detail/9806972
https://avg.163.com/topic/detail/9806971
https://avg.163.com/topic/detail/9806956
https://avg.163.com/topic/detail/9806955
https://avg.163.com/topic/detail/9806954
https://avg.163.com/topic/detail/9806952
https://avg.163.com/topic/detail/9806948
https://avg.163.com/topic/detail/9806946
https://avg.163.com/topic/detail/9806933
https://avg.163.com/topic/detail/9806932
https://avg.163.com/topic/detail/9806927
https://avg.163.com/topic/detail/9806924
https://avg.163.com/topic/detail/9806923
https://avg.163.com/topic/detail/9806922
https://avg.163.com/topic/detail/9806921
https://avg.163.com/topic/detail/9806909
https://avg.163.com/topic/detail/9806907
https://avg.163.com/topic/detail/9806903
https://avg.163.com/topic/detail/9806891
https://avg.163.com/topic/detail/9806892
https://avg.163.com/topic/detail/9806890
https://avg.163.com/topic/detail/9806872
https://avg.163.com/topic/detail/9806871
https://avg.163.com/topic/detail/9806842
https://avg.163.com/topic/detail/9806855
https://avg.163.com/topic/detail/9806854
https://avg.163.com/topic/detail/9806853
https://avg.163.com/topic/detail/9806852
https://avg.163.com/topic/detail/9806851
https://avg.163.com/topic/detail/9806838
https://avg.163.com/topic/detail/9806834
https://avg.163.com/topic/detail/9806833
https://avg.163.com/topic/detail/9806831
https://avg.163.com/topic/detail/9806830
https://avg.163.com/topic/detail/9806828
https://avg.163.com/topic/detail/9806827
https://avg.163.com/topic/detail/9806813
https://avg.163.com/topic/detail/9806812
https://avg.163.com/topic/detail/9806811
https://avg.163.com/topic/detail/9806810
https://avg.163.com/topic/detail/9806809
https://avg.163.com/topic/detail/9806800
https://avg.163.com/topic/detail/9806802
https://avg.163.com/topic/detail/9806799
https://avg.163.com/topic/detail/9806789
https://avg.163.com/topic/detail/9806788
https://avg.163.com/topic/detail/9806787
https://avg.163.com/topic/detail/9806786
https://avg.163.com/topic/detail/9806780
https://avg.163.com/topic/detail/9806774
https://avg.163.com/topic/detail/9806777
https://avg.163.com/topic/detail/9806771
https://avg.163.com/topic/detail/9806766
https://avg.163.com/topic/detail/9806768
https://avg.163.com/topic/detail/9806767
https://avg.163.com/topic/detail/9806761
https://avg.163.com/topic/detail/9806760
https://avg.163.com/topic/detail/9806759
https://avg.163.com/topic/detail/9806756
https://avg.163.com/topic/detail/9806752
https://avg.163.com/topic/detail/9806746
https://avg.163.com/topic/detail/9806741
https://avg.163.com/topic/detail/9806734
https://avg.163.com/topic/detail/9806733
https://avg.163.com/topic/detail/9806731
https://avg.163.com/topic/detail/9806730
https://avg.163.com/topic/detail/9806729
https://avg.163.com/topic/detail/9806699
https://avg.163.com/topic/detail/9806728
https://avg.163.com/topic/detail/9806709
https://avg.163.com/topic/detail/9806708
https://avg.163.com/topic/detail/9806704
https://avg.163.com/topic/detail/9806703
https://avg.163.com/topic/detail/9806702
https://avg.163.com/topic/detail/9806701
https://avg.163.com/topic/detail/9806700
https://avg.163.com/topic/detail/9806699
https://avg.163.com/topic/detail/9806697
https://avg.163.com/topic/detail/9806696
https://avg.163.com/topic/detail/9806695
https://avg.163.com/topic/detail/9806694
https://avg.163.com/topic/detail/9806692
https://avg.163.com/topic/detail/9806693
https://avg.163.com/topic/detail/9806690
https://avg.163.com/topic/detail/9806689
https://avg.163.com/topic/detail/9806688
https://avg.163.com/topic/detail/9806686
https://avg.163.com/topic/detail/9806687
https://avg.163.com/topic/detail/9806685
通配符 * 来代表每个目录。
与 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 <== 这里可以输出目前磁盘的状态
本文地址:https://www.yitenyun.com/4750.html







