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.www58058.com/32000

(0)
麥德良麥德良
上一篇 2016-08-15
下一篇 2016-08-15

相關推薦

  • 第一周-Linux Basic

        本文主要介紹了計算機的組成及功能、Linux的發行版、Linux哲學思想、一些基本命令、命令幫助的獲取、文件系統層級結構標準。 一、計算機的組成及功能     計算機由硬件和軟件兩大類組成     硬件   &n…

    Linux干貨 2016-11-28
  • N26-博客作業-week2

    1、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。   cp:copy 復制文件和路徑 cp [OPTION]… [-T] SOURCE DEST cp [OPTION]… SOURCE… DIRECTORY cp [OPTION]… -t DIRECTORY SOURCE&…

    Linux干貨 2017-02-12
  • 學習linux第四天

    Linux學習第4天   Linux內部命令和外部命令    內部命令:實際上是shell程序的一部分,其中包含的是一些比較簡單的linux系統命令,這些命令由shell程序識別并在shell程序內部完成運行,通常在linux系統加載運行時shell就被加載并駐留在系統內存中。內部命令是寫在bashy源碼里面的,其執行速度比外部…

    Linux干貨 2016-10-29
  • 13 文件查找與壓縮

    locate find 壓縮命令 file-roller、compress/uncompress(.Z)、gzip/gunzip(.gz)、bzip2/bunzip2(.bz2)、xz/unxz(.xz) zip/unzip、tar locate 數據源 1)查詢系統上預建的文件索引數據庫      2)依賴于事先構建…

    Linux干貨 2016-08-18
  • Linux下 文件類型不同顏色的含義

    linux 文件顏色的含義 藍色代表目錄 綠色代表可執行文件 紅色表示壓縮文件 淺藍色表示鏈接文件 灰色表示其他文件 紅色閃爍表示鏈接的文件有問題了 黃色表示設備文件 藍色文件———-目錄 白色文件———-一般性文件,…

    Linux干貨 2016-10-18
欧美性久久久久