歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS工作中部分實用命令

CentOS工作中部分實用命令

日期:2017/2/28 14:47:13   编辑:Linux教程

制作交換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 拷貝權限)

更多CentOS相關信息見CentOS 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=14

Copyright © Linux教程網 All Rights Reserved