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

相关推荐

  • linux文件管理

    目录创建删除,软硬链接的区别和注意,file命令的使用,工作中遇到一些情况的处理方法

    2017-11-18
  • Linux第三周总结

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 ~]# who | cut -d ” -f1 | uniq 2、取出最后登录到当前系统的用户的相关信息。 ~]# who|tail -1 3、取出当前系统上被用户当作其默认shell的最多的那个shell ~]# cut -d’:’…

    2017-07-16
  • iptables学习笔记   Netfilter:是Linux操作系统核心层内部的一个数据包处理模块。   Hook point:数据包在Netfilter中的挂载点。(PRE_ROUTIN   ,INPUT,OUTPUT,FORWARD,POST_ROUTING)   iptables 规则组成:四张表+五条链(Ho…

    Linux干货 2016-12-05
  • linux如何获取帮助以及基础目录命名标准

    一、linux的命令分为两种,一种是内建命令,即包含在shell当中的,一种是外部命令,通常保存在 bin目录中。 1、对于内部命令:  通常使用 help COMMAND 2、对于外部命令:  通常使用 man command  mannul的位置/usr/share/man man的内容通常分为以下几块   1、N…

    Linux干货 2016-10-30
  • 启动和内核管理2

    五、自制linux系统     分区并创建文件系统         fdisk /dev/sdb         分两个必要的分区   &n…

    Linux干货 2016-09-18
  • (一)Linux发行版及基础命令简述

    计算机 Linux 发行版 命令 帮助

    2017-12-11