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
下一篇 2016-08-11

相关推荐

  • shell脚本编程基础之二(if、case、for、while、until、continue、break语句使用)

    在shell脚本编程中,我们可以根据命令的状态结果,判断要不要执行下一步,但是有时候要判断的问题不止一个,甚至对问题本身都要做判断;同时问题的结果有时也不止一个,这时要借助简单的逻辑与和逻辑或,就显得很无力;要完成复杂的任务,需要借助一定的流程控制:顺序执行、选择执行、循环执行、同时在脚本执行过程中,有用户交互输入的需; if语句 case语句 for语句 …

    Linux干货 2016-08-21
  • 第一周作业

    # 1.计算机的基本组成和功能: – **存储器**:  实现记忆功能的部件用来存放计算程序及参与运算的各种数据 – **运算器**:  负责数据的算术运算和逻辑运算即数据的加工处理 – **控制器**:  负责对程序规定的控制信息进行分析,控制并协调输入,输出操作或内存访问 – **输入设备**: 实现计算程…

    Linux干货 2016-12-04
  • Linux终端类型

    Linux终端类型 Linux的终端类型包括控制台终端、虚拟终端、伪终端、串行终端、控制终端、图形终端。   终端 要理解伪终端(Pseudo Terminal),先来看看什么是“终端”(Terminal)。 终端是一种字符型设备,它有多种类型,通常使用tty来简称各种类型的终端设备。 1、串行端口终端(/dev/ttySx) 串行端口终端(Ser…

    Linux干货 2016-10-14
  • N21-北京-兔锅-马哥教育网络班21期+第二周课程练习

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 A.wc命令: 功能:统计指定文件中的字节数、字数、行数,并将统计结果显示输出 语法:wc [选项]文件… 参数: -c:统计字节数。 -l:统计行数。 -m:统计字符数。这个标志不能与 -c 标志一起使用。 -w:统计字数。一个字被定义为…

    Linux干货 2016-07-07
  • 马哥linux运维26期开班感悟

         今天的收获,有以下几点      1.自己的公众演说能力很弱,要多多练习,给自己更多的机会。     2.自己想提升自己的心很强,但是自己却不知道该怎么做?     3.即便学完了也只是一个开始,希望自己有一颗归零的心态。

    Linux干货 2017-07-10
  • Linux发展史

    日期:2016-10-12  Bell,MIT与GE的『Multics』系统     早期的计算机还很不普遍,除非是军事或者高科技用途,或者学术单位的学术研究,否则真的很难接触到。而且计算机架构很难使用。那个时候,程序设计者必须先将程序相关的信息在读卡纸上面打洞然后将读卡纸插入卡片阅读机来将信息读入主机中运算…

    Linux干货 2016-10-14