马哥教育网络班21期+第6周课程练习

请详细总结vim编辑器的使用并完成以下练习题

1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#;

[root@localhost ~]# cp /etc/rc.d/rc.sysinit /tmp/
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# vim rc.sysinit 
:%s/^[[:space:]]/#&/

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

[root@localhost ~]# cp /boot/grub/grub.conf /tmp
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# vim grub.conf 
:%s/^[[:space:]]\+//g

3、删除/tmp/rc.sysinit文件中的以#开头,且后面跟了至少一个空白字符的行行的#和空白字符

[root@localhost tmp]# vim rc.sysinit
:%s/^#[[:space:]]\+//g

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

[root@localhost tmp]# vim grub.conf
:1,3s/^/#/

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

[root@localhost ~]# vim /etc/yum.repos.d/CentOS-Media.repo 
:%s/enabled=0/enabled=1/
:%s/gpgcheck=0/gpgcheck=1/

6、每4小时执行一次对/etc目录的备份,备份至/backup目录中,保存的目录名为形如etc-201504020202

[root@localhost ~]#crontab -e
* */4 * * * cp -rf /etc /backup/etc-`date +\%Y\%m\%d\%H\%M`

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

[root@localhost ~]#crontab -e
0 0 * * 2,4,6 cp /var/log/messages /backup/messages_logs/messages-`date +\%Y\%m\%d

8、每天每两小时取当前系统/proc/meminfo文件中的所有以S开头的信息至/stats/memory.txt文件中

[root@localhost ~]#crontab -e
0 */2 * * * grep "^S" /proc/meminfo >> /stats/memory.tx

9、工作日的工作时间内,每两小时执行一次echo "howdy"

[root@localhost ~]#crontab -e
0 */2 * * 1-5 echo "howdy

脚本编程练习

10、创建目录/tmp/testdir-当前日期时间;

#!/bin/bash
#
mkdir -p /tmp/testdir-`date +\%Y\%m\%d\H\%M`

11、在此目录创建100个空文件:file1-file100

#!/bin/bash
#
for i {1..100};do
  touch file$i
done

12、显示/etc/passwd文件中位于第偶数行的用户的用户名;

#!/bin/bash
#
sed -n 'n;p' /etc/passwd | cut -d ':' f1

13、创建10用户user10-user19;密码同用户名;

#!/bin/bash
#
for i in {10..19}; do
  if id user$i &> /dev/null; then
    echo "user$i exists."
  else
    useradd user$i
    if [ $? -eq 0 ]; then
      echo "user$i" | passwd --stdin user$i &> /dev/null
      echo "Add user$i finished."
    fi
  fi
done

14、在/tmp/创建10个空文件file10-file19;

#!/bin/bash
#
for i in {10..19}; do
  if [ -f file$i ];then
        echo "file$i has exist."
  else
    touch  /tmp/file$i
  fi
done

15、把file10的属主和属组改为user10,依次类推。

#!/bin/bash/
#
for i in {10..19}; do
    chown user$i:user$i /tmp/file$i
done

原创文章,作者:Bazinga,如若转载,请注明出处:http://www.178linux.com/35523

赞 (0)
BazingaBazinga
上一篇 2016-08-15 10:57
下一篇 2016-08-15 11:53

相关推荐

  • 网卡别名和bonding——让你的网络接口更加稳定

    网卡配置文件: 1、IP/NETMASK/GW/DNS等属性的配置文件:/etc/sysconfig/network-scripts/ifcfg-IFACE     IFACE:接口名称 2、路由的相关配置文件(默认无此文件):/etc/sysconfig/network-scripts/route-IFACE 3、配置文件/etc/sy…

    Linux干货 2016-09-05
  • iptables基础详解

    一.iptables基础认知二.iptables使用格式  一.iptables简介   1.Iptabels是与Linux内核集成的包过滤防火墙系统,几乎所有的linux发行版本都会包含Iptables的功能。如果 Linux 系统连接到因特网或LAN、服务器或连接 LAN 和因特网的代理服务器, 则Iptables有利于在 …

    2017-05-03
  • 网络班N22期第六周博客作业

    请详细总结vim编辑器的使用并完成以下练习题 打开文件: ~]# vim [options] [file ..]       +#:打开文件后,直接让光标处于第#行       +/PART…

    Linux干货 2016-09-26
  • 快速部署MySQL高可用方案:heartbeat + drbd + mysql

    实验环境: VIP:192.168.198.200 data1-1:        eth0:192.168.198.140  #用于外网管理IP        eth1:10.0.0.7   #传递心跳信息,…

    Linux干货 2015-10-05
  • 脚本又见脚本,作业又是作业_第七周

    1、创建一个10G分区,并格式为ext4文件系统; (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; [root@centos ~]# fdisk -l &n…

    Linux干货 2016-12-30
  • 构建一个高可用的Nginx集群

    实验目的: 构建一个高可用的Nginx集群。 实验要求: 1、基于nat结构实现; 2、实现高可用; 实验拓扑图形: 实验步骤: 1、  按图配置各个网卡地址; 2、  设置Nginx主机(下面带#的部分为从所需要的配置,其他则一样) Yum install httpd nginx Vim /etc/httpd/conf/httpd.co…

    2017-05-15

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-17 15:30

    写的很好,排版也很棒,加油,第6题不对