df command, du command, disk partition

Disk management

df command

df=disk filesystem is a command used to view the total capacity, usage, remaining capacity and other information of the mounted disk. It can be used directly without any parameters. The default unit of capacity is kilobytes (KByte).

[root@test-01 ~]# df
文件系统          1K-块   已用     可用 已用% 挂载点
/dev/sda3      16659456 872980 15786476    6% /
devtmpfs         929836      0   929836    0% /dev
tmpfs            935392      0   935392    0% /dev/shm
tmpfs            935392   8692   926700    1% /run
tmpfs            935392      0   935392    0% /sys/fs/cgroup
/dev/sda1        201388  75920   125468   38% /boot

The following mount points in the above information, like / , /boot , are the partitions we divide when installing the system; /dev , /dev/shm , which are memory partitions, the default size is 1/2 of the memory, If we save the file in this partition, the file will disappear after reboot. Other partitions like /run, /sys/fs/cgroup are temporary partitions, and these partitions do not need to be moved during normal work.

Common parameters of the df command, -i,-h,-k,-m

  • df -i: Indicates to check the usage of inodes. If inodes are used 100%, even if there is space in the partition, you cannot write anything in it, and the system will prompt that the disk space is full.
[root@test-01 ~]# df -i
文件系统          Inode 已用(I)  可用(I) 已用(I)% 挂载点
/dev/sda3      16669696   23863 16645833       1% /
devtmpfs         232459     365   232094       1% /dev
tmpfs            233848       1   233847       1% /dev/shm
tmpfs            233848     409   233439       1% /run
tmpfs            233848      13   233835       1% /sys/fs/cgroup
/dev/sda1        204800     330   204470       1% /boot

** A little trick, many of the contents displayed directly by this command are temporary partitions and memory partitions, which affect us to view the disk information we need. You can use df -i | grep -v tmpfs , the meaning behind the pipe character is to filter out Partition content with tmpfs. The display content of df -i | grep -v tmpfs can be clearly seen, the temporary partition and memory partition will not be displayed

[root@test-01 ~]# df -i | grep -v tmpfs
文件系统          Inode 已用(I)  可用(I) 已用(I)% 挂载点
/dev/sda3      16669696   23863 16645833       1% /
/dev/sda1        204800     330   204470       1% /boot

  • df -h indicates that the content is displayed in an adaptive appropriate capacity unit
  • df -k and df -m respectively indicate that the display operation in KB and MB is as follows:
[root@test-01 ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda3        16G  853M   16G    6% /
devtmpfs        909M     0  909M    0% /dev
tmpfs           914M     0  914M    0% /dev/shm
tmpfs           914M  8.5M  906M    1% /run
tmpfs           914M     0  914M    0% /sys/fs/cgroup
/dev/sda1       197M   75M  123M   38% /boot
[root@test-01 ~]# df -k
文件系统          1K-块   已用     可用 已用% 挂载点
/dev/sda3      16659456 873004 15786452    6% /
devtmpfs         929836      0   929836    0% /dev
tmpfs            935392      0   935392    0% /dev/shm
tmpfs            935392   8664   926728    1% /run
tmpfs            935392      0   935392    0% /sys/fs/cgroup
/dev/sda1        201388  75920   125468   38% /boot
[root@test-01 ~]# df -m
文件系统       1M-块  已用  可用 已用% 挂载点
/dev/sda3      16269   853 15417    6% /
devtmpfs         909     0   909    0% /dev
tmpfs            914     0   914    0% /dev/shm
tmpfs            914     9   906    1% /run
tmpfs            914     0   914    0% /sys/fs/cgroup
/dev/sda1        197    75   123   38% /boot

du command

du =disk useage is used to view the size of the space occupied by a file or directory, the format is du_ [parameter] filename _ The commonly used parameters of this command are: -a , -b , -k , -m , -s , -c , -h

  • -a : Indicates that the size of the space occupied by all files and directories is listed. If the du command does not add any parameters, it will only list the size of the directory (including subdirectories). If du does not specify a unit, the default display unit is KB.
[root@test-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
12	/root/.bash_history
12	/root/.ssh/.authorized_keys.swp
4	/root/.ssh/authorized_keys
16	/root/.ssh
0	/root/4
0	/root/pawd
56	/root
[root@test-01 ~]# du /root
16	/root/.ssh
0	/root/4
56	/root

du - b ,-k .-m indicates that the space unit is displayed in Byte, KB, MB. The du -c command, which means the final sum, is not commonly used. The du -s command, which only lists the sum, is commonly used.

disk partition

  • Adding disks, most servers now support hot-swappable disks. In the power-on state, directly insert new disks, and the system can also recognize them. To use a virtual machine in an experimental environment, you need to restart the virtual machine after adding disks.
  • Use the fdisk command to view the list of disk devices and partitions in the system. fdisk -l , without the device name, will display a list of all disk devices and partitions. fdisk -l plus the device name will list the partition table of the device. The following is the result obtained by running fdisk -l after restarting the virtual machine after adding the hard disk:
[root@test-01 ~]# fdisk -l

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

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     8603647     4096000   82  Linux swap / Solaris
/dev/sda3         8603648    41943039    16669696   83  Linux

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

As we can see above, the newly added hard disk has been recognized by the system, and the name is: /dev/sdb. Next we still use the fdisk command to partition the hard disk.

Common parameters of the fdisk command,

  • -p : Indicates to print the partition status of the current disk.
  • -n: Create a new partition.
  • -w: save and exit
  • -q: means do not save the settings and exit directly
  • -d: Indicates to delete a partition. Let's demonstrate creating a new partition on the new disk:
命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):+8G
分区 1 已设置为 Linux 类型,大小设为 8 GiB

This is the way to create a new partition.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325479067&siteId=291194637