8.9作业

删除/etc/grub2.conf文件中所有以空白开头的行,行首的空白字符

[root@English6 ~]# sed "s@^[[:space:]]\+@@" /etc/grub.conf 
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda2
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS 6 (2.6.32-642.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=UUID=33bb1eff-ce5c-4fd8-954e-191c7fb12e6d rd_NO_LUKS rd_NO_LVM.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-642.el6.x86_64.img


删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行,的行首的#和空白字符

[root@localhost wang]# sed -n "s@^#[[:space:]]\+@@p" /etc/fstab 
/etc/fstab
Created by anaconda on Tue Aug  9 05:48:51 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


在/root/install.log没一行行首增加#号

[root@English6 ~]# sed  "s@^@#@" /root//install.log
#Installing ql2400-firmware-7.03.00-1.el6_5.noarch
#Installing iwl5000-firmware-8.83.5.1_1-1.el6_1.1.noarch
#Installing ql2100-firmware-1.19.38-3.1.el6.noarch
#Installing ivtv-firmware-20080701-20.2.noarch
#Installing libertas-usb8388-firmware-5.110.22.p23-3.1.el6.noarch
#Installing xorg-x11-drv-ati-firmware-7.6.1-2.el6.noarch
#Installing ql2500-firmware-7.03.00-1.el6_5.noarch
#Installing atmel-firmware-1.3-7.el6.noarch
#Installing zd1211-firmware-1.4-4.el6.noarch
#Installing iwl4965-firmware-228.61.2.24-2.1.el6.noarch
#Installing rt61pci-firmware-1.2-7.el6.noarch
#Installing iwl3945-firmware-15.32.2.9-4.el6.noarch
#Installing ql2200-firmware-2.02.08-3.1.el6.noarch
#Installing rt73usb-firmware-1.8-7.el6.noarch
#Installing ipw2100-firmware-1.3-11.el6.noarch
#Installing ql23xx-firmware-3.03.27-3.1.el6.noarch
#Installing ipw2200-firmware-3.1-4.el6.noarch
#Installing rootfiles-8.1-6.1.el6.noarch
#Installing man-pages-3.22-20.el6.noarch
...

在/etc/fstab文件中不以#开头的行的行首增加#号

[root@English6 ~]# sed "s@^[^#]@#&@" /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Thu Jul 21 16:53:41 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=33bb1eff-ce5c-4fd8-954e-191c7fb12e6d /                       ext4    defaults        1 1
#UUID=47c3f22b-7ed9-4ce1-b341-2d95ff6555af /boot                   ext4    defaults        1 2
#UUID=c9eeb128-84ac-402c-bf90-91ef5f355355 /testdir                ext4    defaults        1 2
#UUID=68b451f6-71ee-4631-a98c-c0a201df6009 swap                    swap    defaults        0 0
#tmpfs                   /dev/shm                tmpfs   defaults        0 0
#devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
#sysfs                   /sys                    sysfs   defaults        0 0
#proc                    /proc                   proc    defaults        0 0


在/etc/fstab路径,使用sed命令取出其目录名的基名

[root@English6 ~]# echo "/etc/fstab" | sed "s@.*\<@@"
fstab
[root@English6 ~]# echo "/etc/fstab/" | sed "s@.*\<@@"
fstab/


利用sed取出ifconfig命令中本机的ipv4地址

[root@localhost wang]# ip addr |sed -n '9p'|sed "s@.*inet@@"|sed "s@/.*@@"
 192.168.1.114


统计centos安装关盘中package目录下的rpm文件的以.分隔倒数第二字段的重复次数

[root@localhost boot]# ls /boot/Packages/ | sed "s@\.rpm@@"|sed "s@.*\.@@"|sort|uniq -c
   2000 i686
   2938 noarch
      1 TBL
   4069 x86_64

复制/etc/profile至/tmp/目录,用查找替换命令删除/tmp/profile文件中的行首的空白字符

[root@localhost wang]# cp /etc/profile /wang
[root@localhost wang]# sed  "s@^[[:space:]]*@@" profile 
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}


if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`id -u`
UID=`id -ru`
fi
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi

# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
fi

HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi

export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL

# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
umask 002
else
umask 022
fi

for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then 
. "$i"
else
. "$i" >/dev/null
fi
fi
done

unset i
unset -f pathmunge


复制/etc/rc.d/init.d/functions的每行开头为空白字符的行的行首添加一个#号

[root@localhost wang]# sed "s@^[[:space:]]*@#&@" functions 
## -*-Shell-script-*-
##
## functions	This file contains functions to be used by most or all
##		shell scripts in the /etc/init.d directory.
##
#
#TEXTDOMAIN=initscripts
#
## Make sure umask is sane
#umask 022
#
## Set up a default search path.
#PATH="/sbin:/usr/sbin:/bin:/usr/bin"
#export PATH
#
#if [ $PPID -ne 1 -a -z "$SYSTEMCTL_SKIP_REDIRECT" ] && \
#		( /bin/mountpoint -q /cgroup/systemd || /bin/mountpoint -q /sys/fs/cgroup/systemd ) ; then
#        case "$0" in
#        /etc/init.d/*|/etc/rc.d/init.d/*)
#		_use_systemctl=1
#		;;
#	esac
#fi
#
#systemctl_redirect () {
#	local s
#	local prog=${1##*/}
#        local command=$2
#        local options=""
#
#	case "$command" in
#	start)
#		s=$"Starting $prog (via systemctl): "
#		;;
#	stop)
#		s=$"Stopping $prog (via systemctl): "
#		;;
#	reload|try-reload)
#		s=$"Reloading $prog configuration (via systemctl): "
#		;;
#	restart|try-restart|condrestart)
#		s=$"Restarting $prog (via systemctl): "
#		;;
#	esac
#
#        if [ -n "$SYSTEMCTL_IGNORE_DEPENDENCIES" ] ; then
#                options="--ignore-dependencies"
#        fi
....

如何设置tab缩进为4个字符

set tabstop=4


复制/etc/rc.d/init.d/functions文件至/tmp目录,替换/tmp/functions文件中/etc/sysconfig/init为/var/log

 sed -i 's@/etc/sysconfig/init@/var/log@' /wang/functions 
[root@localhost wang]# grep "/etc/sysconfig/init" /wang/functions 
[root@localhost wang]# grep "/var/log" /wang/functions 
  if [ -f /var/log ]; then
      . /var/log
    # This all seem confusing? Look in /var/log,


删除/tmp/functions文件中所有以#开头,且#后面至少有一个空白字符的行的行首的#号

[root@localhost wang]# sed -i "s@^#\([[:space:]]\+\)@\1@" functions 
[root@localhost wang]# grep "^#" functions 
#
#

原创文章,作者:DYW,如若转载,请注明出处:http://www.178linux.com/32787

(0)
DYWDYW
上一篇 2016-08-10 22:07
下一篇 2016-08-11 09:37

相关推荐

  • nginx基本功能学习

    一、NGINX介绍: Nginx 是一个高性能的 Web 和反向代理服务器, 它具有有很多非常优越的特性:            作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 Nginx 尤其受到虚拟主机提供商的欢迎。能够支持高达 …

    Linux干货 2015-12-19
  • 数组、变量及bash的配置

    数组、变量及bash的配置 变量:存储单个元素的内存空间 数组:存储多个元素的内存空间,相当于多个变量集合 索引:编号从0开始,属于数值索引,索引为自定义格式即为关联数组(bash4.0之后支持) bash数组支持稀疏格式 数组的声明 普通数组declare –a 关联数组 declare –A 普通数组可以不声明直接使用,关联数组必须先声明再使用 数组的赋…

    Linux干货 2016-08-26
  • bash脚本之for循环和while循环及包管理

    一.概述 上一章剩余内容 压缩工具 cpio 复制从或到文件 cpio命令是通过重定向的方式将文件进行打包备份,还原恢复的工具,它可以解压以“.cpio”或者“.tar”结尾的文件。 cpio[选项] > 文件名或者设备名 cpio[选项] < 文件名或者设备名 选项 -o 将文件拷贝打包成文件或者将文件输出到设备上 -i解包,将打包文件解压或将…

    Linux干货 2016-08-24
  • zabbix low-level discover 监控端口

    zabbix通过调用jason格式的输出,实现数据的收集 获取端口的shell脚本   #!/bin/bash port_array=(`netstat -tnl|egrep -i "$1"|awk {'print $4'}|awk -F':' '{if ($NF~/^[0-9]…

    Linux干货 2016-06-09
  • bash脚本编程之算术运算和文件查找

    算数运算在每个编程语言里面是最基本的功能,在bash里面也是.相对于其他编程语言来说在bash里面不能直接以变量加上变量的形式来表现;比如我们先声明两个变量num1和num2然后再做运算。 num1=2 num2=3 echo "$num1+$num2" 2+3 这里我们显示的结果直接为2+3只是做了变量的替换,而不是做两个变量…

    Linux干货 2016-12-23
  • grep、find练习

    1.显示当前系统上root,fedora或user1用户的默认shell [root@study ~]# cat /etc/passwd|grep -E "^(root|fedora|user1)"|cut -d: -f7 /bin/bash /bin/bash /bi…

    Linux干货 2016-11-27