馬哥教育網絡班21期+第6周課程練習

請詳細總結vim編輯器的使用并完成以下練習題

1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#;

[root@localhost ~]# cp /etc/rc.d/rc.sysinit /tmp/
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# vim rc.sysinit 
:%s/^[[:space:]]/#&/

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

[root@localhost ~]# cp /boot/grub/grub.conf /tmp
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# vim grub.conf 
:%s/^[[:space:]]\+//g

3、刪除/tmp/rc.sysinit文件中的以#開頭,且后面跟了至少一個空白字符的行行的#和空白字符

[root@localhost tmp]# vim rc.sysinit
:%s/^#[[:space:]]\+//g

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

[root@localhost tmp]# vim grub.conf
:1,3s/^/#/

5、將/etc/yum.repos.d/CentOS-Media.repo文件中所有的enabled=0或gpgcheck=0的最后的0修改為1;

[root@localhost ~]# vim /etc/yum.repos.d/CentOS-Media.repo 
:%s/enabled=0/enabled=1/
:%s/gpgcheck=0/gpgcheck=1/

6、每4小時執行一次對/etc目錄的備份,備份至/backup目錄中,保存的目錄名為形如etc-201504020202

[root@localhost ~]#crontab -e
* */4 * * * cp -rf /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 cp /var/log/messages /backup/messages_logs/messages-`date +\%Y\%m\%d

8、每天每兩小時取當前系統/proc/meminfo文件中的所有以S開頭的信息至/stats/memory.txt文件中

[root@localhost ~]#crontab -e
0 */2 * * * grep "^S" /proc/meminfo >> /stats/memory.tx

9、工作日的工作時間內,每兩小時執行一次echo "howdy"

[root@localhost ~]#crontab -e
0 */2 * * 1-5 echo "howdy

腳本編程練習

10、創建目錄/tmp/testdir-當前日期時間;

#!/bin/bash
#
mkdir -p /tmp/testdir-`date +\%Y\%m\%d\H\%M`

11、在此目錄創建100個空文件:file1-file100

#!/bin/bash
#
for i {1..100};do
  touch file$i
done

12、顯示/etc/passwd文件中位于第偶數行的用戶的用戶名;

#!/bin/bash
#
sed -n 'n;p' /etc/passwd | cut -d ':' f1

13、創建10用戶user10-user19;密碼同用戶名;

#!/bin/bash
#
for i in {10..19}; do
  if id user$i &> /dev/null; then
    echo "user$i exists."
  else
    useradd user$i
    if [ $? -eq 0 ]; then
      echo "user$i" | passwd --stdin user$i &> /dev/null
      echo "Add user$i finished."
    fi
  fi
done

14、在/tmp/創建10個空文件file10-file19;

#!/bin/bash
#
for i in {10..19}; do
  if [ -f file$i ];then
        echo "file$i has exist."
  else
    touch  /tmp/file$i
  fi
done

15、把file10的屬主和屬組改為user10,依次類推。

#!/bin/bash/
#
for i in {10..19}; do
    chown user$i:user$i /tmp/file$i
done

原創文章,作者:Bazinga,如若轉載,請注明出處:http://www.www58058.com/35523

(0)
BazingaBazinga
上一篇 2016-08-15 10:57
下一篇 2016-08-15 11:53

相關推薦

  • 馬哥教育網絡班22期+第6周課程練習

    請詳細總結vim編輯器的使用并完成以下練習題 1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#; cp /etc/rc.d/rc.sysinit /tmp vim /tmp/rc.sysinit :%s@^[[:space:]]\+@…

    Linux干貨 2016-09-19
  • 馬哥教育網絡班22期+第四周課程練習

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限 [root@localhost ~]# cp -rf /etc/skel/ /home/tuser1 &> /dev/null [root@localhost ~]# chmod -R go= /home/tus…

    Linux干貨 2016-09-07
  • Linux基礎知識(一)-linux哲學思想,基礎命令,FHS

    1.描述計算機的組成及其功能 2.按系列羅列Linux 的發行版,并描述不通發行版之間的聯系和區別. 3.描述Linux的哲學思想,并按照自己的理解對其進行解釋 4.說明Linux系統命令的使用格式,詳細介紹ifconfig,echo,tty,startx,export.pwd,history,shutdown,poweroff,reboot,hwclock…

    Linux干貨 2016-09-22
  • N25第三周作業

    .列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登陸多次,則只顯示一次即可。 此題主要考察命令who,cut,sort以及管道的基本用法:who:列出當前已登陸的用戶名,登陸設備名,時間以及ip地址。 cut:    顧名思義就是截取之意, -d 指定要截取信息的分隔符,此處是以空格為分隔符,-f指定要截取的字段,此…

    Linux干貨 2016-12-20
  • 文本處理和正則表達式練習(0805)

    1、找出ifconfig命令結果中本機的所有IPv4地址     1.1 Centos7     1.2 Centos6 2、查出分區空間使用率的最大百分比值,取各分區利用率的數值 取出各分區數值 取出最大百分比 3、查出用戶UID最大值的用戶名、 UID及shell類型 4、查出/tmp…

    Linux干貨 2016-08-06
  • Linux下的進程調度與作業管理

    Linux下的進程調度與作業管理 一、概述 1.1 進程的相關概念: 通過前面的幾個章節,我們幾乎已經學習了很多的linux的基礎,這個章節我們講一下linux下的進程管理,就像windows 下的進程一樣,我們知道windows 下有一個任務管理器,專門用來管理進程,我們首先看一下windows 的任務管理器: 從這2個圖我們可以看出,windows 下的…

    Linux干貨 2016-10-17

評論列表(1條)

  • 馬哥教育
    馬哥教育 2016-08-17 15:30

    寫的很好,排版也很棒,加油,第6題不對

欧美性久久久久