20160808作业

20160808作业

1、每日课堂笔记总结

2、预习

3、每日课堂pdf练习

1、删除/etc/grub2.cfg文件中所有以空白开头的行行首的空白字符

[root@Centos7 ~]# sed '/^[[:space:]]\+/d' /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 [ -s $prefix/grubenv ]; then
fi
if [ "${next_entry}" ] ; then
else
fi
if [ x"${feature_menuentry_id}" = xy ]; then
else
fi
export menuentry_id_option
if [ "${prev_saved_entry}" ]; then
fi
function savedefault {
}
function load_video {
}
terminal_output console
if [ x$feature_timeout_style = xy ] ; then
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
fi
### END /etc/grub.d/00_header ###
### BEGIN /etc/grub.d/00_tuned ###
set tuned_params=""
### END /etc/grub.d/00_tuned ###
### BEGIN /etc/grub.d/01_users ###
if [ -f ${prefix}/user.cfg ]; then
fi
### END /etc/grub.d/01_users ###
### BEGIN /etc/grub.d/10_linux ###
menuentry 'CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_64-advanced-4b461f3a-1b13-49c9-80eb-0a03f4fa9519' {
}
menuentry 'CentOS Linux (0-rescue-d84e4562ec594069be53afee569c711e) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-d84e4562ec594069be53afee569c711e-advanced-4b461f3a-1b13-49c9-80eb-0a03f4fa9519' {
}
### END /etc/grub.d/10_linux ###
### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###
### BEGIN /etc/grub.d/20_ppc_terminfo ###
### END /etc/grub.d/20_ppc_terminfo ###
### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###
### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###
### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
fi
### END /etc/grub.d/41_custom ###

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

[root@Centos7 ~]# sed '/^#.*[[:space:]]\+/d' /etc/fstab 
#
#
#
UUID=4b461f3a-1b13-49c9-80eb-0a03f4fa9519 /                       xfs     defaults        0 0
UUID=c332bc3c-01b4-40e3-b600-c5791719e14b /boot                   xfs     defaults        0 0
UUID=7561a152-2688-4437-a001-814a4cddd745 /testdir                xfs     defaults        0 0
UUID=bb4c502d-ec7c-4237-811c-30de82daaf68 swap                    swap    defaults        0 0
[root@Centos7 ~]# sed '/^#.*[[:space:]]\+/d' /etc/fstab > f1
[root@Centos7 ~]# diff f1 /etc/fstab 
2a3,4
> # /etc/fstab
> # Created by anaconda on Thu Jul 21 11:21:52 2016
3a6,7
> # 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

3、在f2每一行行首增加#号

[root@Centos7 ~]# sed -r 's/(^.*)/#&/' f2
#21e@3232.com
#maeefe@madede.com
#edweww@ddsds.comdw.dewew@dsdwddw.com
#1111@111.1111.1111@11111.!111
#
#

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

[root@Centos7 ~]# sed 's/^[^#].*/#&/' /etc/fstab 
#
# /etc/fstab
# Created by anaconda on Thu Jul 21 11:21:52 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=4b461f3a-1b13-49c9-80eb-0a03f4fa9519 /                       xfs     defaults        0 0
#UUID=c332bc3c-01b4-40e3-b600-c5791719e14b /boot                   xfs     defaults        0 0
#UUID=7561a152-2688-4437-a001-814a4cddd745 /testdir                xfs     defaults        0 0
#UUID=bb4c502d-ec7c-4237-811c-30de82daaf68 swap                    swap    defaults        0 0

5、处理/etc/fstab路径,使用sed命令取出其目录名和基名

[root@Centos7 ~]# echo "/etc/fstab" |sed -r 's@(.*/)(.*/?)@\1@'
/etc/
[root@Centos7 ~]# echo "/etc/fstab" |sed -r 's@(.*/)(.*/?)@\2@'
fstab

6、利用sed 取出ifconfig命令中本机的IPv4地址

[root@Centos7 ~]# ifconfig|sed -n '2p'|sed -r 's/.*net (.*) netmask.*/\1/'
10.1.252.77

7、统计centos安装光盘中Package目录下的所有rpm文件的以.分隔倒数第二个字段的重复次数

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

vim ~/.vimrc
set ts=4

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

扩展命令模式:%s/\/etc/sysconfig\/init\//var\/log/g

[root@Centos7 ~]# sed -n 's/\/etc\/sysconfig\/init/\/var\/log/pg' /tmp/functions
  if [ -f /var/log ]; then
      . /var/log
    # This all seem confusing? Look in /var/log,

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

sed -r 's/^#.*[[:space:]]+.*/[^#].*/' /tmp/functions

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

(0)
麦德良麦德良
上一篇 2016-08-15 14:31
下一篇 2016-08-15 14:31

相关推荐

  • lvs-DR模型构建高性能集群

    构建环境:centos7.1     Diretor server:172.16.15.131  (  VIP:172.16.15.138 )     Real server:172.16.15.132/133      配置163源 拓扑…

    Linux干货 2016-08-22
  • 22期第四周课程练习

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@localhost tuser1]# cp   -r    /etc/skel/   /ho…

    Linux干货 2016-09-08
  • TCP连接的状态详解以及故障排查

    我们通过了解TCP各个状态,可以排除和定位网络或系统故障时大有帮助。(总结网络上的内容) 1、TCP状态 linux查看tcp的状态命令: 1)、netstat -nat  查看TCP各个状态的数量 2)、lsof  -i:port  可以检测到打开套接字的状况 3)、 &nbs…

    Linux干货 2015-04-03
  • Shell编程基础

    1.编程的基本概念 程序:指令+数据   程序编程风格:   过程式:以指令为中心,数据服务于指令。   对象式:以数据为中心,指令服务于数据。    shell程序:提供了编程能力,解释执行。    计算机:只识别二进制指令;    编程语言: &…

    Linux干货 2016-08-15
  • 学习宣言

            学习计划:每天至少2个小时的学习,循序渐进,先通读再精读。         学习目标:成为运维的高手,走上人生巅峰。      &nb…

    Linux干货 2016-10-25
  • 马哥教育网络班20期-第五周课程作业

    Table of Contents 1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; 2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; 3、打出netstat -tan命令执行结果中以‘LISTEN’,后或跟空白字符结尾的行; 4、添加用户bash, tes…

    Linux干货 2016-07-12