CentOS工作中部分实用命令
制作交换2G分区:
dd if=/dev/zero of=/swapfile bs=1M count=2048
mkswap -f /swapfile 将文件转换成交换分区
swapon /swapfile 激活交换分区
swapon -s 查看当前分区情况,可以确定是否成功
确保开机后能生效,需修改fstab
vim /etc/fstab
/swapfile swap swap defaults 0 0
增加逻辑卷:
1、扩逻辑卷
lvextend -L 100M /dev/vgrhel/lvrhel
lvs
[root@server110 ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lvrhel vgrhel -wi-ao 200.00m
2、更新文件系统
resize2fs /dev/mapper/vgrhel-lvrhel
创建pv、创建卷组、创建逻辑卷,格式化成ext4
[root@localhost ~]# pvcreate /dev/sdc
Writing physical volume data to disk "/dev/sdc"
[root@localhost ~]# vgcreate vgsdc /dev/sdc
Volume group "vgsdc" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vgsdc 1 0 0 wz--n- 5.00g 5.00g
lvcreate -n lvsdc -L 200M /dev/vgsdc
[root@localhost ~]# mkfs.ext4 /dev/vgsdc/lvsdc (逻辑卷格式化成ext4)
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 17G 4.9G 11G 31% /
tmpfs 164M 0 164M 0% /dev/shm
/dev/sda1 194M 26M 159M 14% /boot
/dev/mapper/vgsdc-lvsdc
194M 5.6M 179M 4% /mnt/lvsdc
umount 卸载挂载的磁盘
卸载逻辑卷、卸载卷组、卸载pv
[root@localhost ~]# lvremove /dev/vg2/vo
Do you really want to remove active logical volume vo? [y/n]: y
Logical volume "vo" successfully removed
[root@localhost ~]# vgremove vgc
Volume group "vgc" successfully removed
[root@localhost ~]# pvremove /dev/sdb
Labels on physical volume "/dev/sdb" successfully wiped
3、查询用户为harry,但是用户组不是harry的文件
find / -user harry -a -not -group harry
找出harry拥有的文件,拷贝到目录/opt/dir下
find / -user harry -exec \cp -rfp {} /opt/dir \;(-rf 强制递归,-p 拷贝权限)