马哥教育网络班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
下一篇 2016-08-15

相关推荐

  • 条件选择if 条件判断case 文件查找 find locate 以及压缩和解压缩工具

    1 shell脚本编程之 条件选择if 条件判断case  2 文件查找 find locate 以及压缩和解压缩工具 过程式编程语言:  顺序执行  选择执行  循环执行 条件选择之 if语句 选择执行:   注意:if语句可嵌套    单分支 if 判断条件:then 条件为真的分…

    Linux干货 2016-08-15
  • 输出重定向 输入重定向 管道简单介绍 -20160729

    输出重定向 输入重定向 管道简单介绍 标准输入和输出 我们先来了解下输入和输出的概念: 在计算机中我们了解到计算机的组成部分:其中有输入 输出设备。       输出重定向 对于程序来说: 程序 :指令 + 数据 对于数据来说,数据可以由我们通过键盘输入,或者程序直接使用存储设备上的数据,我们称为读入 数据,程序处理数据后需要返…

    Linux干货 2016-08-04
  • N25第一周作业

    第一周作业 一、计算机由硬件系统和软件系统两部分组成如下: 计算机硬件由CPU、内存、输入设备、输出设备组成。 1、中央处理器(CPU,Central Processing Unit)   CPU的功能主要是对输入指令的判断和运算;CPU包括运算器、控制器和寄存器三部分; (1)、运算器   执行各种算术和逻辑运算操作,计算机运行时,运算…

    Linux干货 2016-12-05
  • 马哥linux0728课程内容

    课堂学习内容   -ahistory list –.bash_histroy 保存历史列表到历史文件 -cclear history list 清空历史列表 -d deletehistory entru 清除历史列表某一条命令 -rread .bash_history 读历史文件中的命令到历史列表…

    Linux干货 2016-08-04
  • Nginx相关配置及其应用

    LB Cluster: 传输层:lvs、nginx、haproxy 应用层:nginx(http, https, smtp, pop, imap), haproxy(http), httpd(http/https), ats, perlbal, pound, … nginx load balancer: tcp/udp   nginx …

    Linux干货 2016-11-11
  • RAID解说

    RAID(RedundantArrays of Inexpensive Disks,RAID),又叫独立的磁盘阵列。有“价格便宜具有冗余能力的磁盘阵列”之意。原理是利用数组方式来作磁盘组,配合数据分散排列的设计,提升数据的安全性。磁盘阵列是由很多价格较便宜的磁盘,组合成一个容量巨大的磁盘组,利用个别磁盘提供数据所产生加成效果提升整个磁盘系统效能。利用这项技术…

    2017-03-14

评论列表(1条)

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

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