基础篇
2018-09-25 本文已影响0人
柒月的天空
Linux学习
一、df命令
二、du命令
三、磁盘分区
一、df命令
1、需要关注的是磁盘的百分比;
[root@centos01 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 27043944 1182128 25861816 5% /
devtmpfs 923844 0 923844 0% /dev
tmpfs 933644 0 933644 0% /dev/shm
tmpfs 933644 8776 924868 1% /run
tmpfs 933644 0 933644 0% /sys/fs/cgroup
/dev/sda1 201380 111400 89980 56% /boot
tmpfs 186732 0 186732 0% /run/user/0
[root@centos01 ~]#
2、df -h参数可以根据磁盘大小以适当的单位显示;tmpfs临时文件、devtmpfs是内存、需要关注的是dev开头的。
[root@centos01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 26G 1.2G 25G 5% /
devtmpfs 903M 0 903M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.6M 904M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 197M 109M 88M 56% /boot
tmpfs 183M 0 183M 0% /run/user/0
[root@centos01 ~]#
3、free命令
[root@centos01 ~]# free
total used free shared buff/cache available
Mem: 1867292 119412 1586324 8780 161556 1570544
Swap: 4194300 0 4194300
[root@centos01 ~]#
4、df -i参数查看inode及inode数量使用状况;df -m以M为单位显示。
[root@centos01 ~]# df -m
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/sda3 26411 1155 25256 5% /
devtmpfs 903 0 903 0% /dev
tmpfs 912 0 912 0% /dev/shm
tmpfs 912 9 904 1% /run
tmpfs 912 0 912 0% /sys/fs/cgroup
/dev/sda1 197 109 88 56% /boot
tmpfs 183 0 183 0% /run/user/0
[root@centos01 ~]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 27043944 1182124 25861820 5% /
devtmpfs 923844 0 923844 0% /dev
tmpfs 933644 0 933644 0% /dev/shm
tmpfs 933644 8776 924868 1% /run
tmpfs 933644 0 933644 0% /sys/fs/cgroup
/dev/sda1 201380 111400 89980 56% /boot
tmpfs 186732 0 186732 0% /run/user/0
[root@centos01 ~]#
二、du命令
1、du用来查看一个文件大小的命令、du -sh /root/查看/root/目录的大小。
[root@centos01 ~]# du
16 ./.ssh
48 .
[root@centos01 ~]# du -sh /root/
48K /root/
[root@centos01 ~]#
2、一个块只能有一个文件,小于4k默认以一个块为准。
[root@centos01 ~]# du
16 ./.ssh
0 ./1
0 ./2
0 ./3
0 ./4
0 ./5
0 ./6
48 .
[root@centos01 ~]#
[root@centos01 ~]# du /root
16 /root/.ssh
0 /root/1
0 /root/2
0 /root/3
0 /root/4
0 /root/5
0 /root/6
48 /root
[root@centos01 ~]#
三、磁盘分区
1、虚拟机设置添加磁盘;真实环境下服务器支持热插拔fdisk -l查看磁盘信息,此处没有新加磁盘信息,需重启虚拟机。
image.png2、fdisk命令,重启后fdisk -l,新的磁盘出现。fdisk /dev/sdb然后m获取帮助。参数:n 创建新的分区;p列出分区;w保存并退出;d删除分区。普通磁盘分区格式为mbr最大支持2T,主分区最多只能划分4个;公式:主分区+扩展分区<=4;创建分区:n。在m帮助的处输入d,删除分区。
[root@centos01 ~]# fdisk -l
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b196f
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 8800255 4194304 82 Linux swap / Solaris
/dev/sda3 8800256 62914559 27057152 83 Linux
[root@centos01 ~]#
[root@centos01 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xfaf07dfa.
Command (m for help): m
Command action
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)
Command (m for help):
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help):
3、先创建扩展分区,再次创建主分区时会提示创建主分区还是逻辑分区
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): e
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Extended and of size 20 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xfaf07dfa
Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 5 Extended
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p):