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

相关推荐

  • linux 网络管理

    1、ifconfig命令格式: ifconfig[interface] 查看IP ifconfig-a 查看全部网卡信息 ifconfigIFACE [up|down] 网卡开启关闭 ifconfigIFACE IP/netmask [up] ifconfigIFACE IP netmask NETMASK 命令立即生效,不能永久保存  &nbsp…

    Linux干货 2017-08-20
  • 计算机的组成及其功能

        计算机是一种能接受和存储信息,并按照存储在其内部的程序对输入的信息进行加工、处理,然后把处理结果输出的高度自动化的电子设备。计算机是由运算器,控制器,存储器,输入装置和输出装置五大部件组成,每一部件分别按要求执行特定的基本功能。如下图所示: (1)  运算器或称算术逻辑单元(Arithmetical and Logica…

    Linux干货 2016-10-30
  • 网卡别名与bonding

    网络接口配置-bonding Bonding简介 Bonding 就是将多块网卡绑定同一IP地址对外提供服务,可以实现高 可用或者负载均衡。然,直接给两块网卡设置同一IP地址 是不可能的。通过bonding,虚拟一块网卡对外提供连接, 物理网卡的被修改为相同的MAC地址。 Bonding模式 Mode 0 (balance-rr) 轮转(Round-robi…

    Linux干货 2016-09-05
  • 用户和组相关配置文件

    1. /etc/passwd文件详解 输入vi /etc/passwd 可以查看此文件的内容 [root@localhost ~]# vi /etc/passwdroot:x:0:0:root:/root:/bin/bash root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/…

    Linux干货 2016-10-23
  • Hello World, Hello Linux.

    文笔不好,请见谅。

    2018-03-26

评论列表(1条)

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

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