马哥教育网络班20期+第6周练习博客

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


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

[root@bogon ~]# cp /etc/rc.d/rc.sysinit  /tmp/rc.sysinit
[root@bogon ~]# vim /tmp/rc.sysinit
[root@bogon ~]#:%s/^[[:space:]]\+/#&/g

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


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

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


[root@bogon ~]#: vim/tmp/rc.sysinit
[root@bogon ~]#: %s/^[[:space:]]\{0,\}#\+//g


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


[root@bogon ~]#: vim/tmp/grub.conf
[root@bogon ~]#: 1,3s/^/#&/g

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


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

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


[root@bogon ~]# crontab -e
* */4 * * * cp -r /etc/ /backup/etc-`date +%Y%m%d%H%M`
[root@bogon ~]# crond start


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


[root@bogon ~]# * * * * */2,4,6 cp -r /var/log/messages /backup/messages_logs/messages-`date +%Y%m%d`


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


[root@bogon ~]# * */2 */1 * * grep "^S" /proc/meminfo >> /stats/memory.txt


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

[root@bogon ~]#  * 9-17/2 * * */1-5 echo "howdy"


脚本编程练习

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


 [root@bogon ~]# vim /tmp/testdir.sh 
 #!/bin/bash
  mkdir -pv /tmp/testdir-$(date +%F-%H-%M-%S)

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


[root@bogon tmp]# 
[root@bogon tmp]# cd testdir-2016-07-18-02-00-47/
[root@bogon testdir-2016-07-18-02-00-47]# touch file{1..100}
[root@bogon testdir-2016-07-18-02-00-47]# ls
file1    file14  file2   file25  file30  file36  file41  file47  file52  file58  file63  file69  file74  file8   file85  file90  file96
file10   file15  file20  file26  file31  file37  file42  file48  file53  file59  file64  file7   file75  file80  file86  file91  file97
file100  file16  file21  file27  file32  file38  file43  file49  file54  file6   file65  file70  file76  file81  file87  file92  file98
file11   file17  file22  file28  file33  file39  file44  file5   file55  file60  file66  file71  file77  file82  file88  file93  file99
file12   file18  file23  file29  file34  file4   file45  file50  file56  file61  file67  file72  file78  file83  file89  file94
file13   file19  file24  file3   file35  file40  file46  file51  file57  file62  file68  file73  file79  file84  file9   file95


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


[root@bogon ~]# cat -n  /etc/passwd | sed -n '2~2p' |cut -d: -f1
     2  bin
     4  adm
     6  sync
     8  halt
    10  uucp
    12  games
    14  ftp
    16  dbus
    18  vcsa
    20  avahi-autoipd
    22  haldaemon
    24  ntp
    26  saslauth
    28  pulse
    30  tcpdump
    32  bash
    34  basher
    36  fedora
    38  dhcpd

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


[root@bogon ~]# cat ./useradd.sh
#!/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 is finished."
    fi
    fi
done

[root@bogon ~]# bash useradd.sh
Add user10 is finished.
Add user11 is finished.
Add user12 is finished.
Add user13 is finished.
Add user14 is finished.
Add user15 is finished.
Add user16 is finished.
Add user17 is finished.
Add user18 is finished.
Add user19 is finished.
[root@bogon ~]#


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


[root@bogon ~]# touch /tmp/file{10..19}


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


[root@bogon ~]# vim ./usertest.sh
#!/bin/bash
cd /tmp
for i in {10..19};do
    chown user$i:user$i /tmp/file$i
done


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

(0)
huan918huan918
上一篇 2016-07-22 10:10
下一篇 2016-07-22 10:10

相关推荐

  • HA专题: 使用pacemaker+corosync实现MySQL高可用

    HA专题: 使用pacemaker+corosync实现MySQL高可用 前言 实验拓扑 实验环境 实验步骤 准备工作 安装HA组件并配置 配置NFS 配置MySQL 配置HA资源 测试 总结 前言 上篇文章我们介绍了使用pacemkaer+corosync实现简单的nginx高可用, 这篇文章我们介绍如何使用pacemaker+corosync实现MySQ…

    Linux干货 2016-04-11
  • grep命令

    alias命令 直接输入 alias 命令会列出当前系统中所有已经定义的命令别名。 例一:列出当前系统中所有已经定义的命令别名。 [root@localhost ~]# alias alias cp=’cp -i’ alias egrep=’egrep –color=auto’ alias fgrep=’fgrep –color=auto’ alias …

    Linux干货 2016-01-09
  • linux 系统启动流程探讨

    linux系统启动流程: linux系统启动流程,按层次分的话,可以分为内核空间的启动与用户空间的启动。 下面先说说内核空间的启动流程。 一个linux要跑起来,在最简陋的情况下,必须有:kernel , lib ,application kernel功能:加载驱动程序,内存管理,进程管理,文件系统,网络管理,安全管理,glibc 库: 是一个函数的集合,每…

    Linux干货 2017-04-11
  • 正则表达式的如何使用

    简述:正则表达式主要用于文本的搜索,它表示了搜索文本的过滤条件。根据这些条件,对目标文本朱行进行匹配检查,最后对输出匹配到符合过滤条件的行。 使用:正确高效的使用正则表达式,需要掌握以下基本知识点         1:语法 grep [OPTION] PATTERN FILE……

    Linux干货 2017-06-04
  • mysql.主从复制.读写分离.高可用.集群实战

    架构图如下: 1.按照架构图所示,准备机器,做好时间同步,主机名解析 192.168.42.150 node1 [proxySQL keepalived]192.168.42.151 node2 [proxySQL keepalived]192.168.42.152 node3 [mysql-master wha]192.168.42.153 node4 […

    Linux干货 2017-07-14
  • 全球敏捷运维峰会Gdevops 2017成都站嘉宾主题提前看!

    2017年全球敏捷运维峰会(Gdevops, Global Devops Summit)将于2017年在成都、上海、北京、广州四城全面启动,本次峰会由上海市经济和信息化委员会指导,上海市云计算产业促进中心、DBAplus社群主办,数十家媒体单位共同支持,活动家提供全球敏捷运维峰会在线报名服务。 成都站即将于13日启航,搭车地址:https://www.huo…

    Linux干货 2017-05-11

评论列表(1条)

  • 马哥教育
    马哥教育 2016-07-22 10:21

    写的很好,排版也很棒,第3 5 好像不对吧,crontab每周,直接写就可以,不用除以,每天也不用除以1,加油