N22-第六周作业

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

单词间跳转

w:下一个单词的词首

e:当前或后一个单词的词尾

b:当前或前一个单词的词首

行首行尾跳转:

^:跳转至行首的第一个非空白字符

0:跳转至行首

$: 跳转至行尾

句间跳转:

)

(

段落跳转:

}

{

字符编辑

x:删除光标所在处的字符

#x:删除光标所在处起始的#个字符

xp:交换光标所在处的字符与其后面的字符的位置

替换命令:

r替换光标所在处的字符

删除命令:

d:可结合光标跳转字符,实现范围删除

粘贴命令

p:缓冲区中的内容如何为整行,则粘贴在当前光标所在行的下方:否则,粘贴至当前光标所在处的后方

P:缓冲区中的内容如何为整行,则粘贴在当前光标所在行的上方:否则,粘贴至当前光标所在处的前方

复制命令

y:复制,工作行为相似于d命令

可视化模式:

v:按字符选定

V:按行选定

结合编辑命令使用:d,c,y

撤销操作:

u:撤销此前的操作

    #u:撤销此前的#个操作

撤销此前的撤销:

    Ctrl+r

重复执行前一个编辑操作

vim命令行模式:

地址定界:

start_pos[,end_pos]

#:特定的第#行,例如5即第五行;

#,#:指定行范围,左侧为起始行,右侧为结束行;

#,+#:指定行范围,左侧为起始行绝对编号,右侧为相对左侧行号的偏移量

点,表示当前号

$:最后一行

%:表示全文

/pattern/:从光标所在处第一次被模式所匹配到的行

查找并替换:

s:命令行模式的命令,使用格式:

        s/要查找内容/替换的内容/修饰符

        要查找的内容:可使用正则表达式

        替换的内容:不能使用正则表达式,但可以引用        

            如果“要查找的内容”部分在模式中使用分组符号:在“替换为的内容”中使用后向引用

            直接引用查找模式匹配到的全部文本

修饰符:i:忽略大小写

                g:全局替换,意味着一行中如果匹配到多次,则均替换


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

[root@localhost ~]# cp /etc/rc.d/rc.sysinit /tmp/rc.sysinit        (先复制/etc/rc.d/rc.sysinit文件至/tmp目录)

[root@localhost ~]# vim /tmp/rc.sysinit        (用vim编辑文件)

在命令行模式输入:%s/^[[:space:]]\+/#&/g

部分截屏:

if [ -x /usr/sbin/system-config-network-cmd ]; then

#  if strstr "$cmdline" netprofile= ; then

#    for arg in $cmdline ; do

#        if [ "${arg##netprofile=}" != "${arg}" ]; then

#           /usr/sbin/system-config-network-cmd –profile ${arg##netprofile=}

#        fi

#    done

#  fi

fi


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

[root@localhost ~]# cp /boot/grub/grub.conf /tmp/grub.conf        (复制/boot/grub/grub.conf至/tmp目录中)

[root@localhost ~]# vim /tmp/grub.conf        (用vim编辑文件)

在命令行模式输入:%s/^[[:space:]]\+//g

部分截屏

default=0

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title CentOS (2.6.32-431.el6.x86_64)

root (hd0,0) 

kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=fec8b8a8-9718-42e2-af47-26e513138aa1 rd_NO_LUKS rd_NO_LVM.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet

initrd /initramfs-2.6.32-431.el6.x86_64.img


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

[root@localhost ~]# sed 's/^#[[:space:]]\+//g' /tmp/rc.sysinit

(部分截屏)

Set up binfmt_misc

/bin/mount -t binfmt_misc none /proc/sys/fs/binfmt_misc > /dev/null 2>&1

Boot time profiles. Yes, this should be somewhere else.

if [ -x /usr/sbin/system-config-network-cmd ]; then

  if strstr "$cmdline" netprofile= ; then

    for arg in $cmdline ; do

        if [ "${arg##netprofile=}" != "${arg}" ]; then

   /usr/sbin/system-config-network-cmd –profile ${arg##netprofile=}

        fi

    done

  fi

fi

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

[root@localhost ~]# sed '1,3 s/^.*/#&/g' /tmp/grub.conf

## 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;

[root@localhost ~]# sed -r 's/(gpgcheck=|enabled=)0/\11/g' /etc/yum.repos.d/CentOS-Media.repo 

部分截屏

gpgcheck=1

enabled=1


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

[root@localhost /]# mkdir backup        (创建备份目录/backup)

[root@localhost /]# crontab -e 

输入如下:

0 */4 * * * /bin/cp -a /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 /bin/cp -a /var/log/messages /backup/messages_logs/messages-$(date +\%Y\%m\%d)


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

[root@localhost /]# crontab -e

输入如下:

0 */2 * * * /bin/grep "^S" /proc/meminfo > /stats/memory.txt


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

0 8-12/2 * * 1-5 echo "howdy"

0 14-18/2 * * 1-5 echo "howdy"


脚本编程练习

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

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

[root@localhost ~]# vim mkd-testdir.sh        (创建脚本)

#!/bin/bash

# Author: liuguohui

# Date: 2016/09/24 17:20

# Email: [email protected]

# Version: 0.0.1

# Description: mkdir a directory and touch one hundred file1-file100 empty file

#

dirname="testdir-$(date +\%Y\%m\%d\%H\%M)"

mkdir /tmp/$dirname

for i in {1..100}

do

touch /tmp/$dirname/file$i

done


[root@localhost ~]# bash mkd-testdir        (执行脚本)

[root@localhost ~]# ls /tmp/testdir-201609241129        (查询结果)

file1    file17  file25  file33  file41  file5   file58  file66  file74  file82  file90  file99

file10   file18  file26  file34  file42  file50  file59  file67  file75  file83  file91

file100  file19  file27  file35  file43  file51  file6   file68  file76  file84  file92

file11   file2   file28  file36  file44  file52  file60  file69  file77  file85  file93

file12   file20  file29  file37  file45  file53  file61  file7   file78  file86  file94

file13   file21  file3   file38  file46  file54  file62  file70  file79  file87  file95

file14   file22  file30  file39  file47  file55  file63  file71  file8   file88  file96

file15   file23  file31  file4   file48  file56  file64  file72  file80  file89  file97

file16   file24  file32  file40  file49  file57  file65  file73  file81  file9   file98


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

[root@localhost ~]# vim show-evenline.sh    (创建脚本)

#!/bin/bash

# Author: liuguohui

# Date: 2016/09/24 19:15

# Email: [email protected]

# Description: display even number line

#

sed -n '2~2p' $1 |cut -d ':' -f 1


[root@localhost ~]# bash show-evenline.sh /etc/passwd        (执行脚本)

bin

adm

sync

halt

uucp

games

ftp

vcsa

postfix


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

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

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

[root@localhost ~]# vim user.sh    (创建脚本)

#!/bin/bash

# Author: liuguohui

# Date: 2016/09/24 19:32

# Email: [email protected]

# Description: useradd user10-user19 and password same to useranme and touch file10-file19

#       file empty and file10-19 owner-user,owner-group change user10-19,group10-19

#

for i in $(seq 10 19);

do

# useradd user

useradd "user$i"

# set password

echo "user$i" | passwd –stdin "user$i"

# touch file

touch /tmp/file$i

# change owner-user and owner-group

chown "user$i":"user$i" /tmp/file$i

done


[root@localhost ~]# bash user.sh        (执行脚本)

Changing password for user user10.

passwd: all authentication tokens updated successfully.

Changing password for user user11.

passwd: all authentication tokens updated successfully.

Changing password for user user12.

passwd: all authentication tokens updated successfully.

Changing password for user user13.

passwd: all authentication tokens updated successfully.

Changing password for user user14.

passwd: all authentication tokens updated successfully.

Changing password for user user15.

passwd: all authentication tokens updated successfully.

Changing password for user user16.

passwd: all authentication tokens updated successfully.

Changing password for user user17.

passwd: all authentication tokens updated successfully.

Changing password for user user18.

passwd: all authentication tokens updated successfully.

Changing password for user user19.

passwd: all authentication tokens updated successfully.


[root@localhost ~]# ll /tmp/        (查询属主和属组)

total 32

-rw-r–r–. 1 user10 user10     0 Sep 24 12:45 file10

-rw-r–r–. 1 user11 user11     0 Sep 24 12:45 file11

-rw-r–r–. 1 user12 user12     0 Sep 24 12:45 file12

-rw-r–r–. 1 user13 user13     0 Sep 24 12:45 file13

-rw-r–r–. 1 user14 user14     0 Sep 24 12:45 file14

-rw-r–r–. 1 user15 user15     0 Sep 24 12:45 file15

-rw-r–r–. 1 user16 user16     0 Sep 24 12:45 file16

-rw-r–r–. 1 user17 user17     0 Sep 24 12:45 file17

-rw-r–r–. 1 user18 user18     0 Sep 24 12:45 file18

-rw-r–r–. 1 user19 user19     0 Sep 24 12:45 file19


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

(0)
heianyangguoheianyangguo
上一篇 2016-09-26 07:41
下一篇 2016-09-26 07:43

相关推荐

  • 学习新技术的10个建议

    我们生活在一个振奋人心的时代。我们可以越来越方便廉价地获得大量学习资源。这些资源的传播载体由最初的教室被变成了博客,技术论坛等。坐拥如此众多的学习资源,我们没有任何理由不去好好利用。随之而来的问题便是如何在这知识的海洋中选择自己的前进方向。在这篇文章中,我将简要概括一些技术学习的建议,希望可以给你带来一些启发。 尽管我的建议主要涉及的是软件开发方面,但是这些…

    Linux干货 2015-03-20
  • grep是个什么鬼

    正则表达式   一个正则表达式是一个描述了一个字符串集合的模式。正则表达式的构造类似于算术表达式,使用各种各样的操作符来将更小的表达式连在一起。 Grep能理解两种不同版本的正则表达式语法:“basic”和“extended”。在GNU grep中,两种语法可以实现的功能是没有区别的。在其他实现中,基本(basic)正则表达式表达能力要弱一点。下面…

    Linux干货 2017-04-17
  • N25_第二周博客作业:

    N25_第二周博客作业: 1、linux上的文件管理命令都有哪些,其常用的使用方法及其相关示例演示。 Linux上常见的文件管理类命令有mkdir、touch、cp、mv、rm、stat。 mkdir:创建新目录 SYNOPSIS   mkdir [OPTION]… DIRECTORY… 常用: 1、直接建目录 [root@…

    Linux干货 2016-12-09
  • 第六周博客作业

    请详细总结vim编辑器的使用并完成以下练习题 1、复制/etc/rc.d/rc.sysinit文件至/tmp目录,将/tmp/rc.sysinit文件中的以至少一个空白字符开头的行的行首加#; cp /etc/rc.d/rc.sysinit /tmp vim /tmp/rc.sysinit :%s@^[[:space:]]\+[^[:space:]]@#&a…

    Linux干货 2017-02-26
  • 源码包编译安装

    程序包编译安装:      Application-VERSION-release.src.rpm–> 安装后,使用rpmbuild命令制作成二进制格式的rpm包,而后再安装      源代码 –> 预处理 –> 编译 &#8…

    Linux干货 2016-08-23
  • Homework Week-7 RAID及bash编程

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

    Linux干货 2016-09-26

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-27 09:46

    写的很好,但是还需要注意下排版的问题