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

df命令

df命令用于查看已挂载磁盘的总量,使用容量,剩余容量,及使用百分比。
命令:df
命令格式:df [选项]
选项:
-h 以最合理的单位查看用量
-m 以M 为单位显示
-i 查看iNode的使用情况
-T 显示文件系统类型
eg:

  • 直接df

     [root@shuai-01 ~]# df
    

这里写图片描述
文件系统那一列,只要是带tmpfs表明是零时文件系统,在所对应的挂在点上,即使写文件,关机或重启之后,也会消失。
/dev/shm 这个是内存,大小是物理内存的一半。

  • -h选项

      [root@shuai-01 ~]# df -h
    

这里写图片描述
以最合理的单位显示

  • -m选项

      [root@shuai-01 ~]# df -m
    

这里写图片描述
以M为单位显示

  • -i选项

      [root@shuai-01 ~]# df -i
    

这里写图片描述
显示iNode的使用情况

  • -T 选项

     [root@shuailinux-01 ~]# df -T
     文件系统       类型        1K-块    已用     可用 已用% 挂载点
     /dev/sda3      xfs      18655232 1560272 17094960    9% /
     devtmpfs       devtmpfs   490124       0   490124    0% /dev
     tmpfs          tmpfs      499968       0   499968    0% /dev/shm
     tmpfs          tmpfs      499968    6784   493184    2% /run
     tmpfs          tmpfs      499968       0   499968    0% /sys/fs/cgroup
     /dev/sda1      xfs        201380  111568    89812   56% /boot
     tmpfs          tmpfs       99996       0    99996    0% /run/user/0
    

可以常看磁盘分区对应的文件系统

free命令:显示内存和swap(交换分区)的使用情况

[root@shuai-01 ~]# free
              total        used        free      shared  buff/cache   available
Mem:         999936      108884      734396        6808      156656      721252
Swap:       2097148           0     2097148

du命令

du命令是用来查看某个文件或目录的大小
命令:du
命令格式:du [选项] 文件或目录名
选项:
-h 以合理的单位显示内存
-s 只显示总和(及当前目录)
-a 能将所有文件都显示出来,包括子目录,孙目录。

eg:

  • -s选项

     [root@shuai-01 ~]# du -s /root/
     56	/root/
    

    只查看当前文件

  • -h选项

      [root@shuai-01 ~]# du -h /root
     16K	/root/.ssh
     0	/root/shuai/aoli
     0	/root/shuai/deng
     0	/root/shuai
     0	/root/deng
     56K	/root
    

以合理单位显示

  • -a 选项

      [root@shuai-01 ~]# 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简单粗暴

	[root@shuai-01 ~]# du -sh /root/
	56K	/root/

磁盘分区

这是很重要的一块,认真对待。

  1. 添加一个新磁盘,给虚拟机。
    在虚拟机中添加一个新磁盘
    这里写图片描述
    一直下一步(SCSI)到指定磁盘空间
    这里写图片描述
    下一步完成
    这里写图片描述
    这是就添加成功了,但是还不能被识别出来
    fdisk -l 可查看所有硬盘
    这时就要重启才能识别。

  2. 重启,识别新硬盘

     [root@shuai-01 ~]# reboot
    
    [root@shuai-01 ~]# 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 字节
    

就能识别出来了。

  1. fdisk 磁盘划分分区
    命令:fdisk
    命令格式:fdisk 磁盘名

    [root@shuai-01 ~]# 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。作为了解:
http://www.apelearn.com/bbs/thread-7243-1-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值