-
1 、刪除/etc/grub2.cfg 文件中所有以空白開頭的行行首的 空白字符
[root@localhost ~]# sed -r 's@^[[:space:]]+@@' /etc/grub2.cfg
-
2 、刪除/etc/fstab 文件中所有以#開頭,后面至少跟一個空白字符的行的行首的# 和空白字符
[root@localhost ~]# sed -r 's@^#[[:space:]]+@@' /etc/fstab
-
3 、在/etc/fstab 文件中不以# 開頭的行的行首增加#號
[root@localhost ~]# sed -r 's@^[^#]@#&@' /etc/fstab # # /etc/fstab # Created by anaconda on Mon Jul 25 12:04:17 2016 # # 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=f4406f6a-e495-45a0-a85e-3b059c0d3130 / xfs defaults 0 0 #UUID=7c25120e-2371-413d-b584-fdd695b96702 /boot xfs defaults 0 0 #UUID=19470291-724c-4f01-b6e1-7109ad22be1b /usr xfs defaults 0 0 #UUID=c3460309-9e8c-4037-8684-4c6bdcabbacb swap swap defaults 0 0
-
4 、處理/etc/fstab 路徑, 使用sed 命令取出其目錄名和基名
[root@localhost ~]# echo "/etc/fstab" |sed -r 's@/.*/([^/]+/?)$@\1@' fstab [root@localhost ~]# echo "/etc/fstab" |sed -r 's@(/.*/)[^/]+/?$@\1@' /etc/
-
5 、利用sed 取出ifconfig 命令中本機的IPv4 地址
[root@localhost ~]# ifconfig |sed -n 2p|sed 's@netmask.*@@'|sed 's@inet@@' 10.1.252.131
-
6 、統計centos 安裝光盤中Package 目錄下的所有rpm 文件的以.分隔倒數第二個字段的重復次數
[root@localhost Packages]# ls *.rpm | sed -r 's@.*\.(.*).rpm@\1@'|sort|uniq -c 1912 i686 2895 noarch 3845 x86_64
-
7 、復制/etc/profile 至/tmp/ 目錄,用查找替換命令刪除 /tmp/profile 文件中的行首的空白字符
:%s@^[[:space:]]\+@@
-
8、復制/etc/rc.d/init.d/functions 文件至/tmp 目錄,用查找替換命令為/tmp/functions 的每行開頭為空白字符的行的 行首添加一個#號
:%s@^[[:space:]]\+@#&@
原創文章,作者:dxkboke,如若轉載,請注明出處:http://www.www58058.com/32544