一、vim編輯器的使用
二、練習題
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.www58058.com/34655
排版非常的漂亮,圖片知識點總結的非常棒,6題是每隔4小時,7題還需要確定到小時,你的答案是每周2,4,6的每小時的0分執行,加油!