請詳細總結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.www58058.com/35578
完成的非常的好,8題差一個”/”, 1 */2 * * * ,9題差一個工作時間哈,加油!