這份作業與常見的 Linux 基礎題組類似,重點在於把「建立使用者所需的一整套前置作業」手動做一遍,再用正則表達式做資料提取。
[root@xu 桌面]# cp -r /etc/skel /home/tuser1 [root@xu 桌面]# chmod -R 700 /home/tuser1/
[root@xu 桌面]# vim /etc/group [root@xu 桌面]# tail -1 /etc/group hadoop:x:2005:
[root@xu 桌面]# id hadoop uid=2005(hadoop) gid=2005(hadoop) 組=2005(hadoop)
[root@xu 桌面]# cp -R /etc/skel /home/hadoop [root@xu hadoop]# chmod 700 /home/hadoop
[root@xu hadoop]# chown -R hadoop:hadoop /home/hadoop [root@xu hadoop]# ls -l /home 總用量 36 drwx------. 5 hadoop hadoop 4096 8月 25 23:57 hadoop
[root@xu hadoop]# grep -i ^s /proc/meminfo SwapCached: 0 kB SwapTotal: 2031612 kB SwapFree: 2031612 kB Shmem: 4348 kB Slab: 101132 kB SReclaimable: 32508 kB SUnreclaim: 68624 kB [root@xu hadoop]# grep ^[sS] /proc/meminfo
# 7. 預設 shell 非 /sbin/nologin 的用戶
grep -v '/sbin/nologin' /etc/passwd | cut -d: -f1
# 8. 預設 shell 為 /bin/bash 的用戶
grep "/bin/bash" /etc/passwd | cut -d: -f1
# 9. 抓取一位數或兩位數
grep "\<[0-9]\{1,2\}\>" /etc/passwd
# 10. 以空白字元開頭的行
grep "^[[:space:]]" /boot/grub/grub.conf
# 11. # 後接空白再接非空白的行
grep "^#[[:space:]]\+[^[:space:]]\+" /etc/rc.d/rc.sysinit
# 12. netstat 結果中以 LISTEN 結尾的行
netstat -tan | grep 'LISTEN[[:space:]]*$'
[root@xu 桌面]# useradd bash [root@xu 桌面]# useradd testbash [root@xu 桌面]# useradd basher [root@xu ~]# useradd -s /sbin/nologin nologin
這份作業的價值在於:真正常用的帳號管理指令(useradd、usermod、groupadd)背後,其實就是對 /etc/passwd、/etc/group 這兩個文字檔的增修。理解這一層,除錯時才不會盲。