马哥教育网络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.178linux.com/35578

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

相关推荐

  • Shell编程基础

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

    Linux干货 2016-08-15
  • 马哥教育网络班22期+第5周课程练习

    1、显示当前系统上root、fedora或user1用户的默认shell; [root@localhost ~]# awk -F: '{print $1,$7}' /etc/passwd| egrep "^\<(root|fedora|user…

    Linux干货 2016-09-15
  • ☞磁盘管理、MBR、GPT、分区工具、文件系统、常见分区挂载

    磁盘管理{磁盘结构;MBR;GPT;分区工具;文件系统;分区挂载;}

    Linux干货 2016-08-29
  • 软件包管理器之二——YUM介绍及使用

    一、前言     之前我们介绍了RPM的应用(详细请查看http://www.178linux.com/archives/6383),发觉RPM安装软件有一个很繁琐的问题,那就是包与包之间的依赖关系,如果想正常安装和使用软件程序,就必须根据要求一步一步的解决软件之间的依赖关系。那么如果程序使用的包很多,将会很消耗使用人…

    Linux干货 2015-07-21
  • 管道:管道符;cat和more命令 重定向:文件标识符:I/O重定向符号及其用法;exec命令;代码块重定向 命令行处理:命令行处理流程;eval命令 管道: 管道是Linux编程中最常用的技术之一,Shell编程中竖杠符号:“|” command1 | command2 | command3 | … |commandn command1到commandn表…

    Linux干货 2016-08-05
  • Linux Basics-Linux Bash历史和其概念名词解释part1

    Linux Basics-Linux Bash历史和其概念名词解释part1 阅读本文你将知道:查看更多BashFAQ.pdf   Bash的历史及其特性   Bash的如何工作   Bash的概念解释   前提知识:      对linux有一定基础而且了解Bash的…

    Linux干货 2016-10-29

评论列表(1条)

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

    完成的非常的好,8题差一个”/”, 1 */2 * * * ,9题差一个工作时间哈,加油!