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

相关推荐

  • LINUX命令帮助

    命令帮助 在维护和使用Linux系统时,常常会遇到忘记命令的使用方法,遇到一个比较陌生的命令,又或者想知道这个命令是什么的情况可以查看命令使用帮助。 LINUX命令使用帮助可参考:程序自身的帮助文档、官方文档、官方站点、LINUX的发行版官方文档、其他网站或者搜索引擎 LINUX命令分为内部命令(shell内置的命令)和外部命令,内部命令和外部命令…

    Linux干货 2017-05-28
  • iptables防火墙

    Linux防火墙基础 在Internet中,企业通过架设各种应用系统来为用户提供各种网络服务,例如Web网站,电子邮件系统,FTP服务器,数据库系统等等,而防火墙就是用来保护这些服务器,过滤企业不需要的访问甚至是恶意的入侵。 Linux防火墙体系主要工作在网络层,针对TCP/IP数据包实施过滤和限制,属于典型的包过滤防火墙。Linux防火墙体系基于内核编码实…

    Linux干货 2017-01-10
  • 正则表达式

    正则表达式 热身 正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串、将匹配的子串做替换或者从某个串中取出符合某个条件的子串等。 例如 grep, expr, sed , awk. 或Vi中经常会使用到正则表达式,为了充分发挥&…

    Linux干货 2016-08-12
  • Linux 第五天: (08月01日) 练习和作业

    Linux 第五天: (08月01日) 练习和作业         创建用户gentoo, 附加组为bin和root, 默认shell为/bin/csh, 注释信息为"Gentoo Distribution" useradd -G bin,root -c "Gentoo Distribut…

    Linux干货 2016-08-08
  • mount挂载

    mount 1 挂载mount                                               &nb…

    Linux干货 2017-04-24
  • 用户管理相关

    安全3A:     资源分配:       authentication:认证       authorization 授权       accouting|audition 审计 用户分为(centos7):   管理员:root 0 &…

    Linux干货 2017-02-25