df命令、du命令、磁盘分区

4.1 df命令

[vitus@24centos7-01 ~]$ df
文件系统          1K-块    已用     可用 已用% 挂载点
/dev/sda3      29140072 1184728 27955344    5% /
devtmpfs         494372       0   494372    0% /dev
tmpfs            504196       0   504196    0% /dev/shm
tmpfs            504196    6736   497460    2% /run
tmpfs            504196       0   504196    0% /sys/fs/cgroup
/dev/sda1        201380  111492    89888   56% /boot
tmpfs            100840       0   100840    0% /run/user/1000
  • -m以MB单位显示分区使用情况
[vitus@24centos7-01 ~]$ df -m
文件系统       1M-块  已用  可用 已用% 挂载点
/dev/sda3      28458  1157 27301    5% /
devtmpfs         483     0   483    0% /dev
tmpfs            493     0   493    0% /dev/shm
tmpfs            493     7   486    2% /run
tmpfs            493     0   493    0% /sys/fs/cgroup
/dev/sda1        197   109    88   56% /boot
tmpfs             99     0    99    0% /run/user/1000

  • -h参数指采取合适的单位显示
[vitus@24centos7-01 ~]$ df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda3        28G  1.2G   27G    5% /
devtmpfs        483M     0  483M    0% /dev
tmpfs           493M     0  493M    0% /dev/shm
tmpfs           493M  6.6M  486M    2% /run
tmpfs           493M     0  493M    0% /sys/fs/cgroup
/dev/sda1       197M  109M   88M   56% /boot
tmpfs            99M     0   99M    0% /run/user/1000
  • -i 查看iNode使用情况
[vitus@24centos7-01 ~]$ df -i
文件系统          Inode 已用(I)  可用(I) 已用(I)% 挂载点
/dev/sda3      14577152   32762 14544390       1% /
devtmpfs         123593     327   123266       1% /dev
tmpfs            126049       1   126048       1% /dev/shm
tmpfs            126049     380   125669       1% /run
tmpfs            126049      16   126033       1% /sys/fs/cgroup
/dev/sda1        102400     330   102070       1% /boot
tmpfs            126049       1   126048       1% /run/user/1000

4.2 du命令

du = disk useage的简写,用来查看某个目录或文件所占空间的大小,最常用的是du -sh

[root@24centos7-01 ~]# du -sh /etc/
24M	/etc/
[root@24centos7-01 /]# du -sh /sbin/
37M	/sbin/

4.3磁盘分区

增加虚拟磁盘不再描述,在vmware中添加一块即可

fdisk命令----分区工具,只能使用在小于2T分区

[root@24centos7-01 usr]# fdisk
用法:
 fdisk [选项] <磁盘>    更改分区表
 fdisk [选项] -l <磁盘> 列出分区表
 fdisk -s <分区>        给出分区大小(块数)

选项:
 -b <大小>             扇区大小(512、1024、2048或4096)
 -c[=<模式>]           兼容模式:“dos”或“nondos”(默认)
 -h                    打印此帮助文本
 -u[=<单位>]           显示单位:“cylinders”(柱面)或“sectors”(扇区,默认)
 -v                    打印程序版本
 -C <数字>             指定柱面数
 -H <数字>             指定磁头数
 -S <数字>             指定每个磁道的扇区数

  • -l参数
--查看当前所有磁盘信息
[root@24centos7-01 usr]# fdisk -l  

磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0002f5a8

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
/dev/sda3         4605952    62914559    29154304   83  Linux

--添加一块磁盘后再次查看相关信息
[root@24centos7-01 ~]# fdisk -l
--第一块磁盘
磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0002f5a8

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
/dev/sda3         4605952    62914559    29154304   83  Linux

--第二块磁盘,刚刚添加的,未分区的
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

使用fdisk对磁盘/dev/sdb进行分区,一块磁盘最多分4个主分区,或者3个主分区,1个扩展分区

  • 1个主分区
[root@24centos7-01 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x0e9ecc64 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):m                 --此处输入m查看分区菜单

命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel               //编辑分区标签
   c   toggle the dos compatibility flag
   d   delete a partition               //删除一个分区
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu                  //打印此菜单
   n   add a new partition              //添加一个新分区
   o   create a new empty DOS partition table
   p   print the partition table        //打印当前磁盘的分区情况
   q   quit without saving changes      //不保存退出
   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)


命令(输入 m 获取帮助):n                //输入n,创建新分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)      //主分区输入p
   e   extended                                     //扩展分区输入e
Select (default p): p                               //输入p选择主分区
分区号 (1-4,默认 1):
起始 扇区 (2048-20971519,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-20971519,默认为 20971519):+2000M       //设定分区大小为2GB
分区 1 已设置为 Linux 类型,大小设为 2 GiB


命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   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)

命令(输入 m 获取帮助):w                //输入w保存并退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@24centos7-01 ~]# 

  • 1个扩展分区
--先查看下磁盘分区情况
[root@24centos7-01 ~]# fdisk -l /dev/sdb

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x6bca4892

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4098047     2048000   83  Linux

--分区
[root@24centos7-01 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   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)

命令(输入 m 获取帮助):n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): e
分区号 (2-4,默认 2):
起始 扇区 (4098048-20971519,默认为 4098048):
将使用默认值 4098048
Last 扇区, +扇区 or +size{K,M,G} (4098048-20971519,默认为 20971519):
将使用默认值 20971519
分区 2 已设置为 Extended 类型,大小设为 8 GiB

命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   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)
命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@24centos7-01 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

[root@24centos7-01 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   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)

命令(输入 m 获取帮助):n
Partition type:
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)                //扩展分区需进一步分为逻辑分区
Select (default p): l
添加逻辑分区 5
起始 扇区 (4100096-20971519,默认为 4100096):
将使用默认值 4100096
Last 扇区, +扇区 or +size{K,M,G} (4100096-20971519,默认为 20971519):
将使用默认值 20971519
分区 5 已设置为 Linux 类型,大小设为 8 GiB

--分区完毕,打印当前磁盘的分区信息
命令(输入 m 获取帮助):p

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x6bca4892

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4098047     2048000   83  Linux
/dev/sdb2         4098048    20971519     8436736    5  Extended
/dev/sdb5         4100096    20971519     8435712   83  Linux


猜你喜欢

转载自my.oschina.net/u/3585954/blog/1560119