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

一、vim编辑器的使用

VIM使用.png

二、练习题

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

[root@www ~]# cp /etc/rc.d/rc.sysinit /tmp
[root@www ~]# ls /tmp
copyfstab  inittab  rc.sysinit  src  yum.log
[root@www ~]# vim /tmp/rc.sysinit 
-bash: vim: command not found
[root@www ~]# yum install -y vim
[root@www ~]# !vim
:%s/^[[:space:]]/#&/

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

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

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

[root@www ~]# vim /tmp/rc.sysinit
:%s/^#[[:sapce:]]\+//

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

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

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

[root@www tmp]# vim CentOS-Media.repo 
:%s/=0/=1/g

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

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

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

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

6-9说明如下:

[root@www tmp]# crontab -e
[root@www tmp]# crontab -l
0 */3 * * * root cp -a -r /etc /backup/messages_logs/etc-`date +%Y%m%d%H%M`
0 * * * 2,4,6 root cp -a -r /var/log/messages /backup/messages_logs/messages-`date +%Y%m%d`
0 */2 * * * root grep -i ^s /proc/meminfo &>>/stats/memory.txt
0 6-18/2 * * 1-5 root echo "howdy"

三、脚本编程练习

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

[root@www tmp]# mkdir /tmp/test-`date +%Y%m%d%H%M`

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

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

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

[root@www test-201608130946]# sed -n 'n;p' /etc/passwd

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

[root@www tmp]# cat useradd-test.sh 
#!/bin/bash

for i in {10..19};do
	useradd user$i && echo "user$i" | passwd --stdin user$i
	echo "user$i created!"
done

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

[root@www tmp]# cat touchfile-test.sh 
#!/bin/bash

for i in {10..19};do
        touch file$i
	echo "file$i created!"
done

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

[root@www tmp]# cat touchfile-test.sh 
#!/bin/bash

for i in {10..19};do
        chown file$i user$i:user$i
	echo "chown file$i ok!"
done

原创文章,作者:N21-孟然,如若转载,请注明出处:http://www.178linux.com/34655

(0)
N21-孟然N21-孟然
上一篇 2016-08-15 12:06
下一篇 2016-08-15 12:06

相关推荐

  • systemd

    systemd的新特性(centos 7) 系统引导时实现服务并行启动 按需激活进程,在此之前可以让进程处于半活动状态 系统状态快照:能够自我保存当前系统上没一个用户空间的进程运行状态快照,将来可以迅速恢复到某一种状态,因此用户空间有了时间机器。可以回滚到过去某一时刻的状态 内在的基于依赖关系定义的服务控制逻辑 对与systemd来讲,引入了一个新的核心概念…

    Linux干货 2016-09-23
  • 配置Nginx作为反向代理服务器

    配置Nginx作为反向代理服务器      一、nginx作为反向代理的工作模型: 1、nginx作为反向代理的工作模型       nginx工作在应用层,其能理解并可以提取出http请求报文中的首部信息中的请求方法、url、http协议版本等信息。   &…

    Linux干货 2016-10-29
  • vsftpd、nfs、samba

    I/O:网络、存储 存储: DAS:Direct Attached Storage 接口类型:“block”;只有块设备才能够进行分区格式化 设备:SATA,SAS;IDE,SCSI;USB; NAS:Network Attached Storage(网络附加存储) 接口类型:”file” 协议:CIFS(samba), NFS(Ne…

    Linux干货 2017-06-13
  • Linux中的文本处理工具

    本章内容:   一、各种文本工具来查看、分析,统计文本文件   二、grep   三、正则表达式   四、扩展正则表达式   五、Sed 具体内容如下: 一、抽取文本的工具:      文件内容:less和cat      文件截取:head和tai…

    Linux干货 2016-08-08
  • 主从DNS 子域授权 基于域的转发和DNS视图的配置

    先把软件包的安装: yum install bind yum install bind-utils(DNS的查询工具,dig nslookup host) 事先我已经安装好了。 主从DNS的网络拓扑图: 主从DNS配置: 主从DNS服务器的同步可以有:完全区域同步(AXFR)和增量区域同步(IXFR),配置过程中要注意,增量备份时,需要调整区域文件中的SOA…

    Linux干货 2015-08-24
  • N22-冥界之王-第9周作业

    第九周    1、写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);   分别这两类用户的个数;通过字符串比较来实现;     declare -a shell  &n…

    Linux干货 2016-11-01

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-07 22:40

    排版非常的漂亮,图片知识点总结的非常棒,6题是每隔4小时,7题还需要确定到小时,你的答案是每周2,4,6的每小时的0分执行,加油!