df命令\du命令\磁盘分区4.1-4.4
df 查看已挂载磁盘的总容量、使用容量、剩余容量等,可以不加任何参数,默认是按k为单位显示的
第一列是分区的名字,第二列为该分区总共的容量,第三列为已经使用了多少,第四列为还剩下多少,第五列为已经使用百分比,如果这个数值到达90%以上应该注意,会引起系统崩溃的
df常用选项有:
-i :查看inodes使用状况
-h :使用合适的单位显示,例如 ‘G’
-k :以 K 为单位显示
-m :以M 为单位显示
二、du命令
du命令是用来查看某个文件或目录的大小
命令:du
命令格式:du [选项] 文件或目录名
选项:
-h 以合理的单位显示内存
-s 只显示总和(及当前目录)
-a 能将所有文件都显示出来,包括子目录,孙目录。
例如:
-s选项
只查看当前文件
du -s /root/
56 /root/
-h选项
以合理单位显示
du -h /root
16K /root/.ssh
0 /root/shuai/aoli
0 /root/shuai/deng
0 /root/shuai
0 /root/deng
56K /root
-a 选项
隐藏文件,子目录子文件,孙目录,当前目录,全都显示。
du -a /root/
4 /root/.bash_logout
4 /root/.bash_profile
4 /root/.bashrc
4 /root/.cshrc
4 /root/.tcshrc
4 /root/anaconda-ks.cfg
8 /root/.bash_history
4 /root/.ssh/known_hosts
4 /root/.ssh/id_rsa
4 /root/.ssh/id_rsa.pub
4 /root/.ssh/authorized_keys
16 /root/.ssh
0 /root/shuai/aoli
0 /root/shuai/deng
0 /root/shuai/3.txt
0 /root/shuai
0 /root/deng/1.txt
0 /root/deng/shuai
0 /root/deng
4 /root/1.txt.bak
4 /root/1.txt
56 /root/
常用du -sh filename简单直观
du -sh /root/
258k /root
*(重要) 三、磁盘分区
因为我们用的是虚拟机,所以要先给虚拟机添加一块磁盘,按如下操作方法添加:
1、先关闭正在运行的Linux系统 ,使用命令 init 0
2、到vmware的Linux虚拟机界面,点 “Edit virtual machine settings”, 点一下左侧靠下面的 “Add…” 按钮
3、在左侧选中 “Hard Disk” 默认就是这一行,点右下角的 “Next”, 继续点 “Next”
4、“Virtual disk type” 选择 IDE,点 “Next”
5、继续点 “Next”, “Disk size” 默认即可,最后点 “Finish”
fdisk -l 可查看所有硬盘 这时就要重启才能识别。
重启,识别新硬盘
reboot
fdisk -l
磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0008a618
设备 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 41943039 18668544 83 Linux
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
就能识别出来了。
fdisk 磁盘划分分区
命令:fdisk
命令格式:fdisk 磁盘名
fdisk /dev/sdb
进去磁盘分区
按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)
n:表示建立一个新分区
w:表示保存
p:表示打印当前分区情况
q:表示退出(不保存)
d:删除一个分区
添加一个主分区
命令(输入 m 获取帮助):n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
分区号 (2-4,默认 2):
起始 扇区 (10487808-20971519,默认为 10487808):
将使用默认值 10487808
Last 扇区, +扇区 or +size{K,M,G} (10487808-20971519,默认为 20971519):+1G
分区 2 已设置为 Linux 类型,大小设为 1 GiB
添加一个扩展分区
命令(输入 m 获取帮助):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): e
分区号 (3,4,默认 3):
起始 扇区 (12584960-20971519,默认为 12584960):
将使用默认值 12584960
Last 扇区, +扇区 or +size{K,M,G} (12584960-20971519,默认为 20971519):+2G
分区 3 已设置为 Extended 类型,大小设为 2 GiB
添加完扩展分区后就可以添加逻辑分区了
命令(输入 m 获取帮助):n
Partition type:
p primary (2 primary, 1 extended, 1 free)
l logical (numbered from 5)
Select (default p): l
添加逻辑分区 5
起始 扇区 (12587008-16779263,默认为 12587008):
将使用默认值 12587008
Last 扇区, +扇区 or +size{K,M,G} (12587008-16779263,默认为 16779263):+1G
分区 5 已设置为 Linux 类型,大小设为 1 GiB
打印出添加的分区
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x230515a6
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
/dev/sdb2 10487808 12584959 1048576 83 Linux
/dev/sdb3 12584960 16779263 2097152 5 Extended
/dev/sdb5 12587008 14684159 1048576 83 Linux
主分区和扩展分区在(sdb1~sdb4)这里,而逻辑分区,在sdb5到以后。
删除分区
命令(输入 m 获取帮助):d
分区号 (1-3,5,默认 5):2
分区 2 已删除
分完区后,想保存,按w退出,不想保存,按q退出。
ps: 关于主分区,扩展分区,和逻辑分区的关系。主分区加逻辑分区只能有4个,而且其中扩展分区最多只能有一个。逻辑分区是只能存在扩展分区里面,并且逻辑分区区号从5开始,依次排下去。
ps:fdisk这个分区工具,只能划分小于2TB的分区,并且,主分区只能有4个。而GPT分区格式,突破了这些限制,它没有主分区、扩展分区、逻辑分区之分,在一块磁盘上最多可以分128个分区出来,支持大于2T的分区,最大卷可达18EB。
扩展知识:
parted分区gpt格式
http://www.apelearn.com/bbs/thread-7243-1-1.html