1. 程式人生 > >馬哥Linux雲端計算架構班--第三週學習作業

馬哥Linux雲端計算架構班--第三週學習作業

1、定義一個對所有使用者都生效的命令別名,例如:lftps='lftp 172.168.0.1/pub'

echo "alias cdnet='cd /etc/sysconfig/network-scripts/'" >> /etc/bashrc
source /etc/bashrc

2、顯示/etc/passwd 檔案中不以/bin/bash結尾的行

grep -v /bin/bash /etc/passwd

3、找出/etc/passwd 檔案中,包含二位數字或者三位數的行

grep [[:digit:]]{2,3} /etc/passwd

4、顯示/proc/meminfo 檔案中以大寫或小寫S開頭的行;用三種方式實現

grep -i ^S /proc/meminfo

5、使用echo輸出一個絕對路徑,使用egrep取出路徑名,型別執行dirname /etc/passwd的結果

不會

6、找出ifconfig中的ip地址,要求結果只顯示ip地址

ifconfig | grep '((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d))).){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))'

7、vim定製自動縮排四個字元

set tabstop=4(但自己玩了一下是8個縮排的)

8、編寫指令碼,實現自動新增三個使用者,並計算這三個使用者的uid之和

#!/bin/bash
useradd user1
useradd user2
useradd user3
hangshu = "cut -d: -f3 /etc/passwd | wc -l"
user1uid = "cut -d: -f3 /etc/passwd | tail -n $hangshu"
user2uid = "cut -d: -f3 /etc/passwd | tail -n $hangshu-1"
user3uid = "cut -d: -f3 /etc/passwd | tail -n $hangshu-2"
uidsum = $user1uid + $user2uid + $user3uid
echo $uidsum

9、find用法以及常用用法的例項演示

find / -name /etc/passwd
find / -name /etc/passwd -exec cp -r /tmp {} \;
find / -size 2K /etc/passwd