【04-04】 删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
【04-04】 删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
# 备份文件到root家目录做测试 [root@centos-7 ~]# cp /etc/fstab /root/fstab #查看该文件 [root@centos-7 ~]# cat /root/fstab # # /etc/fstab # Created by anaconda on Thu Mar 7 06:38:37 2019 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=4b499d76-769a-40a0-93dc-4a31a59add28 / ext4 defaults 1 1 #对文件进行处理 /^# 取得各行已#开头的行后传递给 s进行替换 s/^#// 替换为空后进行对文件修改 [root@centos-7 ~]# sed -ri.bak '/^#/s/^#//' /root/fstab [root@centos-7 ~]# cat /root/fstab /etc/fstab Created by anaconda on Thu Mar 7 06:38:37 2019 Accessible filesystems, by reference, are maintained under '/dev/disk' See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info UUID=4b499d76-769a-40a0-93dc-4a31a59add28 / ext4 defaults 1 1 # 增加一个条件删除前方空格 [root@centos-7 ~]# sed -ri.bak '/^#/s/^#//;/^ /s/^ //' /root/fstab [root@centos-7 ~]# cat fstab /etc/fstab Created by anaconda on Thu Mar 7 06:38:37 2019 Accessible filesystems, by reference, are maintained under '/dev/disk' See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info UUID=4b499d76-769a-40a0-93dc-4a31a59add28 / ext4 defaults 1 1 #删除#号行和空行 [root@centos-7 ~]# sed -i.bak '/^# */d;/^$/d' /root/fstab [root@centos-7 ~]# cat fstab UUID=4b499d76-769a-40a0-93dc-4a31a59add28 /
浙公网安备 33010602011771号