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

(0)
DYWDYW
上一篇 2016-08-10 22:07
下一篇 2016-08-11 09:37

相關推薦

  • 第一周博客作業-Linux發行版歷史、哲學思想、FHS、命令格式、幫助等

    All + All – 第一周作業 1.計算機組成及功能 計算機組成 硬件 馮諾依曼體系 CPU 運算器 對數據做算暖蘇運算和邏輯運算 控制器 寄存器等 程序的運行,是CPU通過調用硬盤中的程序至內存中執行來實現的 存儲器 內存 ROM RAM 外存 硬盤 光盤 輸入設備 鼠標、麥克風等 實現指令和參數的輸入 輸出設備 顯示器、打印機等 實現結果…

    Linux干貨 2017-07-02
  • Linux簡介和基礎

    一、系統和硬件 無論是Linux、OS X、Windows操作系統,他們都是由以下部分組成(分層結構): 最底層:硬件 底層之上:將硬件的接口抽象成為系統調用(kernel) 再之上:庫 再此之上為:應用程序 程序的運行可以有兩種方式: 1、開機自動啟動運行 2、用戶通過交互式接口登陸或者連接系統上去,來手動運行程序 二、終端: 1、物理終端:我們可以將顯示…

    Linux干貨 2017-09-02
  • bash的基礎特性之一

    bash的基礎特性之一 命令歷史:shell進程會保存會話中此前用戶使用過的命令; history:命令的用法 history 【-c】【-d #】 【n】或者【文件名】     -c:清空命令歷史     -d 【#】:刪除指定的命令歷史…

    Linux干貨 2016-12-18
  • lvs簡介

    一、 LVS簡介         LVS是Linux Virtual Server的簡稱,也就是Linux虛擬服務器, 是一個由章文嵩博士發起的自由軟件項目,它的官方站點是www.linuxvirtualserver.org?,F在LVS已經是 Linux標準內核的一部分,在Linux2.4…

    Linux干貨 2016-10-30
  • mysql/mariadb基于ssl的主從復制

     當mysql/mariadb跨越互聯網進行復制時別人可以竊取到mysql/mariadb的復制信息, 這些信息是明文的, 因此存在不安全性, 這里通過ssl對復制的信息進行加密      1. 創建證書中心 在主服務器上創建證書中心 cd /etc/pki/CA 生成私鑰 (umask&…

    Linux干貨 2016-12-05
  • 源碼安裝http

    http://xxlii.blog.51cto.com/10277731/1841570     哈哈!

    Linux干貨 2016-08-24
欧美性久久久久