1、删除/etc/grub2.conf文件中所有以空白开头的行行首的空白字符
[root@localhost ~]# sed -r 's/^[[:space:]]//' /etc/grub2.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
### BEGIN /etc/grub.d/00_header ###
set pager=1
if [ -f ${config_directory}/grubenv ]; then
load_env -f ${config_directory}/grubenv
elif [ -s $prefix/grubenv ]; then
load_env
fi
if [ "${next_entry}" ] ; then
set default="${next_entry}"
set next_entry=
save_env next_entry
set boot_once=true
else
set default="${saved_entry}"
fi
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
else
menuentry_id_option=""
fi
2、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符
[root@localhost ~]# sed -r "s/^#[[:space:]]*//" /etc/fstab
/etc/fstab
Created by anaconda on Sat Oct 22 12:45:03 2022
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.
After editing this file, run 'systemctl daemon-reload' to update systemd
units generated from this file.
UUID=6beb0f09-220d-4fdd-ad09-3739c16a0c06 / xfs defaults 0 0
UUID=8450c75d-6fc1-4e25-9bc0-d48589712f53 /boot xfs defaults 0 0
UUID=de1476ec-158d-4c6a-a52e-304410038adc none swap defaults 0 0
3、在/root/install.log每一行行首增加#号
[root@localhost ~]# sed -n "s/^.*$/#&/" /root/install.log
4、在/etc/fstab文件中不以#开头的行的行首增加#号
[root@localhost ~]# sed -r "s/^[^#]/#&/" /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Oct 22 12:45:03 2022
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
#UUID=6beb0f09-220d-4fdd-ad09-3739c16a0c06 / xfs defaults 0 0
#UUID=8450c75d-6fc1-4e25-9bc0-d48589712f53 /boot xfs defaults 0 0
#UUID=de1476ec-158d-4c6a-a52e-304410038adc none swap defaults 0 0
5、利用sed 取出ifconfig命令中本机的IPv4地址
[root@localhost ~]# ifconfig | sed -n 2p | sed -r "s/.*inet[[:space:]]*//" | sed -r "s/[[:space:]].*//"
192.168.190.133
6、关闭本机SELinux的功能
[root@localhost ~]# sed -i "s/^SELINUX=enforcing/SELINUX=disabled/" /etc/sysconfig/selinux
7、在/etc/hosts配置文件中添加内容
[root@localhost ~]# sed -i "1 i \hello" /etc/hosts
[root@localhost ~]# cat /etc/hosts
hello
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.190.133 www.zuoye.com