月考二

一、10 個選擇題(每個題 2 分,共 20 分) (加黑的為選擇答案)
1、查看當(dāng)前 linux 各分區(qū)的大小及使用情況的命令是什么?
A、du -lh
B、df -lh
C、ls -lh
D、fdisk -l /dev/sd[a-z]
2、使用 fdisk 對磁盤進(jìn)行分區(qū)時,LVM 分區(qū)的類型為
A、l
B、lvm
C、9e
D、8e
3、有關(guān)以下有關(guān) bash 特殊變量說法錯誤的有
A、$0:在腳本中用于引用傳遞給腳本名稱本身;
B、$#:保存?zhèn)鬟f給當(dāng)前腳本的參數(shù)的個數(shù);
C、$?:保存上一條命令的執(zhí)行結(jié)果成功是否的狀態(tài),取值范圍為 0-100;
D、$*:保存?zhèn)鬟f給當(dāng)前腳本的所有參數(shù);
4、兩塊磁盤實驗 RAID1 之后,整體性能會變
A、好
B、差
C、不變
D、變成 2 倍讀寫
5、取出 file 文件中有數(shù)字的那一行并輸出行號,下面正確的是
A、grep -n '[0-9]' file
B、grep '[0-9]' file
C、grep '^[0-9]' file
D、grep '0-9' file
6、下列關(guān)于 grep 方法,錯誤的是
A、-a :將 binary 文件以 text 文件的方式查找數(shù)據(jù)
B、-v :反向選擇,即顯示出沒有‘查找字符串'內(nèi)容的那一行
C、-i :忽略大小寫的區(qū)別,即把大小寫視為相同
D、-l :只顯示文件具體內(nèi)容
7、下列關(guān)于 linux 常見文件類型錯誤的是
A、NFS
B、ext2
C、swap
D、sda
8、下列不是磁盤管理的 linux 命令有
A、fdisk
B、mkfs
C、fsck
D、top
9、有關(guān) RAID 以下說法錯誤的是
A、raid0,對數(shù)據(jù)讀寫均有提升,可以提供數(shù)據(jù)冗余能力,至少需要 3 塊磁盤
B、raid1 對數(shù)據(jù)有冗余能力,寫數(shù)據(jù)能力略有下降
C、raid4 讀寫性能均有提升,有冗余能力
D、raid4 讀寫性能均有提升,有冗余能力
10、如何在命令航中快速刪除光標(biāo)前的內(nèi)容
A、ctrl + u
B、ctrl + k
C、ctrl + e
D、ctrl + b
二、5個簡單題(每個題 7 分,共 35 分)
1、編寫腳本,實現(xiàn)自動添加三個用戶,并計算這三個用戶的 uid 之和

#!/bin/bash
read -p "Please input 3 usernames: " username1 username2 username3
useradd $username1
useradd $username2
useradd $username3
uid1=`grep $username1 /etc/passwd | cut -d: -f3`
uid2=`grep $username2 /etc/passwd | cut -d: -f3`
uid3=`grep $username3 /etc/passwd | cut -d: -f3`
let sum=$uid1+$uid2+$uid3
echo "uid 之和等于:$sum"
驗證
[root@laowei01 ~]#bash uid_sum.sh 
Please input 3 usernames: han xiao long   
uid 之和等于:3156
.....
han:x:1051:1051::/home/han:/bin/bash
xiao:x:1052:1052::/home/xiao:/bin/bash
long:x:1053:1053::/home/long:/bin/bash

2、找出 ifconfig 中的 ip 地址。要求結(jié)果只顯示 IP 地址

[root@laowei01 ~]#ifconfig | grep -E "\<inet\>" | sed -nr 's/^[^0-9]+([0-9.]+)[[:blank:]]+.*$/\1/p'
192.168.44.101
127.0.0.1  

3、簡述 raid 的優(yōu)缺點

RAID-0:讀寫提升,無容錯,多個并聯(lián)
RAID-1:讀提升,寫略下降,鏡像,有冗余,50%利用率
RAID-5:讀寫提升,可用N-1,最多只能壞一塊,每塊硬盤上都有1個校驗位
RAID-6:讀寫提升,可用N-2,最多只能壞兩塊,每塊硬盤上都有2個校驗位
RAID-10(1和0組合):讀寫提升,先1后0,容錯性好
RAID-01(1和0組合):讀寫提升,先0后1,容錯性差

4、簡述 grep 常用選項,最少寫 10 項

-m #:匹配多少次后停止
-v  忽略匹配到的行
-i  忽略字符大小寫
-n  顯示匹配的行號
-c  統(tǒng)計匹配的行數(shù)
-o  僅顯示匹配到的字符串
-q  靜默模式,不輸出任何信息
-A # after, 后#行
-B # before, 前#行
-C # context, 前后各#行
-w  匹配整個單詞
-E  使用ERE(擴展正則表達(dá)式) 

5、添加用戶 bash,testbash,basher 及 nologin,前三個用戶默認(rèn) shell 為/bin/bash,nologin 默認(rèn) shell 為/sbin/nologin,而后找出用戶名與 shell 名相同的用戶;

[root@laowei01 ~]#grep -E "^([^:]+):.*\<\1$" /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
bash:x:1054:1054::/home/bash:/bin/bash
nologin:x:1057:1057::/home/nologin:/sbin/nologin 

三、3個實戰(zhàn)題(每題 15 分,共 45 分)
1、用 shell 腳本求 1 至 101 之間所有奇數(shù)之和,其中 51-60(包含 51 和 60)之間的數(shù)不參與計算

#!/bin/bash
for((i=1;i<=101;i++))
do
    var=$[$i%2]
    [ $var -ne 0 ] && [ $i -lt 51 -o $i -gt 60 ] && let sum+=$i
done
echo $sum
計算結(jié)果:
[root@laowei01 ~]#bash sum_odd.sh 
2326

2、創(chuàng)建一個 LV,要求大小為 10G,名稱為 mylv,指定卷組為 bjwf,并掛載到/data 上

[root@laowei01 ~]#lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0  100G  0 part /
├─sda3   8:3    0    4G  0 part [SWAP]
└─sda4   8:4    0   95G  0 part /data
sdb      8:16   0   20G  0 disk 
└─sdb1   8:17   0   20G  0 part 
sr0     11:0    1 10.3G  0 rom
[root@laowei01 ~]#pvcreate /dev/sdb1                          #創(chuàng)建物理卷
  Physical volume "/dev/sdb1" successfully created.
[root@laowei01 ~]#vgcreate bjwf /dev/sdb1                     #創(chuàng)建卷組
  Volume group "bjwf" successfully created
[root@laowei01 ~]#lvcreate -n mylv -L 10G bjwf                #創(chuàng)建邏輯卷
  Logical volume "mylv" created.
[root@laowei01 ~]#lvdisplay 
  --- Logical volume ---
  LV Path                /dev/bjwf/mylv
  LV Name                mylv
  VG Name                bjwf
  LV UUID                pnp9JL-ukcw-NO6I-TlUo-ZECY-G6H2-VByWF8
  LV Write Access        read/write
  LV Creation host, time laowei01.localdomain, 2020-04-13 17:24:00 +0800
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
[root@laowei01 ~]#mkfs.xfs /dev/bjwf/mylv                           #創(chuàng)建文件系統(tǒng)
meta-data=/dev/bjwf/mylv         isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@laowei01 ~]#mount /dev/bjwf/mylv /data                       #掛載邏輯卷
[root@laowei01 ~]#lsblk 
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0  200G  0 disk 
├─sda1          8:1    0    1G  0 part /boot
├─sda2          8:2    0  100G  0 part /
├─sda3          8:3    0    4G  0 part [SWAP]
└─sda4          8:4    0   95G  0 part /data
sdb             8:16   0   20G  0 disk 
└─sdb1          8:17   0   20G  0 part 
  └─bjwf-mylv 253:0    0   10G  0 lvm  /data
sr0            11:0    1 10.3G  0 rom

3、創(chuàng)建一個 raid5

[root@laowei01 ~]#mdadm -C /dev/md0 -a yes -l 5 -n 3  /dev/sdb /dev/sdc /dev/sdd
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@laowei01 ~]#mkfs.xfs /dev/md0
meta-data=/dev/md0               isize=512    agcount=16, agsize=654720 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=10475520, imaxpct=25
         =                       sunit=128    swidth=256 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=5120, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@laowei01 ~]#mdadm -D /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Mon Apr 13 17:36:14 2020
        Raid Level : raid5
        Array Size : 41908224 (39.97 GiB 42.91 GB)
     Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
      Raid Devices : 3
     Total Devices : 3
       Persistence : Superblock is persistent

       Update Time : Mon Apr 13 17:36:54 2020
             State : clean 
    Active Devices : 3
   Working Devices : 3
    Failed Devices : 0
     Spare Devices : 0

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

              Name : laowei01.localdomain:0  (local to host laowei01.localdomain)
              UUID : 9a6eb5f0:1892e846:e818bdde:730ab905
            Events : 20

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       1       8       32        1      active sync   /dev/sdc
       3       8       48        2      active sync   /dev/sdd
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容