df命令
功能:用来检查linux服务器的文件系统的磁盘空间占用情况
1、df
直接输入默认以1kb为单位输出[root@test ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
8682228 4978244 3256292 61% /
tmpfs 250996 0 250996 0% /dev/shm
/dev/sda1 487652 33252 428800 8% /boot
/dev/sdb 20511356 3580988 15881792 19% /data
2、人性化输出
[root@test ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
8.3G 4.8G 3.2G 61% /
tmpfs 246M 0 246M 0% /dev/shm
/dev/sda1 477M 33M 419M 8% /boot
/dev/sdb 20G 3.5G 16G 19% /data
3、以inode模式来显示磁盘使用情况
[root@test ~]# df -ih
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/VolGroup-lv_root
547K 80K 468K 15% /
tmpfs 62K 1 62K 1% /dev/shm
/dev/sda1 126K 38 125K 1% /boot
/dev/sdb 1.3M 6.0K 1.3M 1% /data
4、列出文件系统的类型
[root@test ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
ext4 8.3G 4.8G 3.2G 61% /
tmpfs tmpfs 246M 0 246M 0% /dev/shm
/dev/sda1 ext4 477M 33M 419M 8% /boot
/dev/sdb ext4 20G 3.5G 16G 19% /data
du命令
命令是对文件和目录磁盘使用的空间的查看
1、直接输出du,输出当前目录的文件及文件夹大小,默认以KB为单位
[root@test ~]# du
4 ./.subversion/auth/svn.ssl.server
4 ./.subversion/auth/svn.ssl.client-passphrase
4 ./.subversion/auth/svn.username
8 ./.subversion/auth/svn.simple
24 ./.subversion/auth
52 ./.subversion
2、当根盘系统满了,可以如下检测
[root@test ~]# du -sh /*
6.0M /bin
31M /boot
4.0K /cgroup
3.4G /data
244K /dev
29M /etc
267M /home
168M /lib
21M /lib64
16K /lost+found
16K /mage
4.0K /media
359M /mnt
3、对单个目录容量检查
[root@test ~]# du -sh /mnt/
359M /mnt/
磁盘分区:fdisk
1、查看磁盘分区情况
fdisk -l
在vmware上新增一块磁盘
2、重启虚拟机
fdisk -l查看磁盘
root@test76 ~]# fdisk -l
看到了20GB的磁盘/dev/sdb
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x000cb2ef
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 1306 9972736 8e Linux LVM
Disk /dev/sdb: 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
3、[root@test76 ~]# fdisk /dev/sdb
Command (m for help): 在这里按 m ,就会输出帮助;
d delete a partition 注:这是删除一个分区的动作
l list known partition types 注:l 是列出分区类型,以供我们设置相应分区的类型;
m print this menu 注:m 是列出帮助信息;
n add a new partition 注:添加一个分区;
p print the partition table 注:p 列出分区表
q quit without saving changes 注:不保存退出;
t change a partition's system id 注:t 改变分区类型;
w write table to disk and exit 注:把分区表写入硬盘并退出;
4、新增一个2G的主分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G
Command (m for help): p
Disk /dev/sdb: 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: 0x2f8fd7be
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
5、再新增一个1G的主分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (263-2610, default 263):
Using default value 263
Last cylinder, +cylinders or +size{K,M,G} (263-2610, default 2610): +1G
Command (m for help): P
Disk /dev/sdb: 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: 0x2f8fd7be
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb2 263 394 1060290 83 Linux
6、新增一个4G的逻辑分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 3
First cylinder (395-2610, default 395):
Using default value 395
Last cylinder, +cylinders or +size{K,M,G} (395-2610, default 2610): +4G
Command (m for help): p
Disk /dev/sdb: 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: 0x2f8fd7be
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2104483+ 83 Linux
/dev/sdb2 263 394 1060290 83 Linux
/dev/sdb3 395 917 4200997+ 5 Extended
7、写入磁盘
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
8、fdisk -l可以看出有3个分区。