馬哥教育網絡21期+第6周博客練習

請詳細總結vim編輯器的使用并完成以下練習題

1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#;

:%s@\(^[[:space:]]\+\)@#&@g

# Let rhgb know that we're leaving rc.sysinit
if [ -x /bin/plymouth ]; then
#    /bin/plymouth --sysinit

2、復制/boot/grub/grub.conf至/tmp目錄中,刪除/tmp/grub.conf文件中的行首的空白字符;

:%s@\(^[[:space:]]*\)@@g

root (hd0,0) 
kernel /vmlinuz-2.6.32-642.3.1.el6.x86_64 ro root=/dev/mapper/vg_centos6-lv_root rd_NO_LUKS rd_NO_MD rd_LVM_LV=vg_centos6/lv_swap.UTF-8 rd_LVM_LV=vg_centos6/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet crashkernel=auto
initrd /initramfs-2.6.32-642.3.1.el6.x86_64.img

3、刪除/tmp/rc.sysinit文件中的以#開頭,且后面跟了至少一個空白字符的行行的#和空白字符

:%s@\(^#[[:space:]]\+\)@@g

Let rhgb know that we're leaving rc.sysinit

4、為/tmp/grub.conf文件中前三行的行首加#號;

:1,3s@^@#@g

## grub.conf generated by anaconda
##
## Note that you do not have to rerun grub after making changes to this file

5、將/etc/yum.repos.d/CentOS-Media.repo文件中所有的enabled=0或gpgcheck=0的最后的0修改為1;

:%s@enabled=0@enabled=1@ 
:%s@gpgcheck=0@gpgcheck=1@

6、每4小時執行一次對/etc目錄的備份,備份至/backup目錄中,保存的目錄名為形如etc-201504020202

crontab -e
1 */4 * * * /usr/bin/cp /etc /backup/etc-$(date +\%Y\%m\%d\%H\%M)

7、每周2,4,6備份/var/log/messages文件至/backup/messages_logs/目錄中,保存的文件名形如messages-20150402

crontab -e
1 1 * * 2,4,6 /usr/bin/cp /var/log/messages /backup/messages_logs/messages-$(date +\%Y\%m\%d)

8、每天每兩小時取當前系統/proc/meminfo文件中的所有以S開頭的信息至/stats/memory.txt文件中

1 *2 * * * /bin/cat /proc/meminfo |grep '^[sS].*' >> /stats/memory.txt

9、工作日的工作時間內,每兩小時執行一次echo "howdy"

1 */2 * * 1-5 bin/echo "howdy"

腳本編程練習

10、創建目錄/tmp/testdir-當前日期時間; 

[root@CentOS6 ~]# mkdir /tmp/testdir-$(date +%F)

11、在此目錄創建100個空文件:file1-file100

[root@CentOS6 ~]# for((i=1;i<=100;i++)) do touch file${i}; done
[root@CentOS6 ~]# ls
file100  file17  file23  file3   file36  file42  file49  file55  file61  file68  file74  file80  file87  file93 
file11   file18  file24  file30  file37  file43  file5   file56  file62  file69  file75  file81  file88  file94
file12   file19  file25  file31  file38  file44  file50  file57  file63  file7   file76  file82  file89  file95
...

12、顯示/etc/passwd文件中位于第偶數行的用戶的用戶名;

[root@CentOS6 ~]# sed -n 'n;p' /etc/passwd|awk -F: '{print $1}'
bin
adm
sync

13、創建10用戶user10-user19;密碼同用戶名;

#!/bin/bash
#
for i in {10..19};do
        useradd user$i
        echo "user$i" |passwd --stdin user$i
done

14、在/tmp/創建10個空文件file10-file19; 

#!/bin/bash
#
for((i=10;i<=19;i++))
do
touch /tmp/file$i
done

15、把file10的屬主和屬組改為user10,依次類推。

#!/bin/bash
#
for((i=10;i<=19;i++))
do
chown user${i}:user${i} /tmp/file$i
done

原創文章,作者:sandiegoit,如若轉載,請注明出處:http://www.www58058.com/35578

(0)
sandiegoitsandiegoit
上一篇 2016-08-15
下一篇 2016-08-15

相關推薦

  • 安裝CentOS 7.2操作系統

        工具:     VMware Workstation     http://www.vmware.com/cn/products/workstation/workstation-evaluation.html  &nbsp…

    Linux干貨 2016-08-04
  • 網絡管理的相關命令

    今天要說的是有關網絡的一些相關內容,主要介紹的有以下幾點:網絡的服務:Centos6/7中的常用命令,如何手動配置網絡,路由表的相關內容,關于Bond(僅主機模式)網絡接口的配置以及Bridge(橋接)的網絡接口配置。 首先要說的是網絡的服務: 1,Centos6/7的常用網絡的命令: Centos6:禁用網卡:ifconfig 網卡名 down啟用網卡:i…

    2017-09-07
  • yum用法第一篇-簡介及常見用法使用總結

    一、簡介     yum( 全稱為:Yellow dog Updater, Modified),是紅帽(RedHat)家族(RedHat、Fedora、CentOS)中的前端shell的軟件包管理器,主要基于對RPM包的管理,能夠根據配置文件(類似于svn資源庫配置文件)從指定的服務器自動下載RPM包進行安裝,其最大的優勢就是可…

    Linux干貨 2015-09-22
  • 源碼編譯安裝之apache

    工具: Development tools組包 httpd-2.2.9.tar.gz links網站瀏覽工具   安裝apache之前需要安裝編譯需要的環境“Development tools”這個是編譯使用的必須的環境包,使用下面的命令可以安裝。 [root@CentOS6 ~]# yum groupinstall&…

    Linux干貨 2016-08-24
  • 第五周作業

    查看鏈接:http://note.youdao.com/noteshare?id=1ed7b36aa41cbdc1154e3e5b54e43fce

    Linux干貨 2016-09-19
  • 計劃任務和周期性任務

    linux計劃任務     功能:指定未來的某以特定的時間點執行一次任務     命令:at、bathc     at命令:         選項: &nbsp…

    Linux干貨 2016-09-12

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-09-07 17:53

    完成的非常的好,8題差一個”/”, 1 */2 * * * ,9題差一個工作時間哈,加油!

欧美性久久久久