image.png

注:通过练习发现在使用grep时,使用-e选项(即扩展正则表达式),可以避免添加更多的转义字符

1

cp -r /etc/skel /home/tuser1 && chmod -R 000 /home/tuser1

image.png

image.png

2

vi /etc/group

image.png

3

Vi /etc/passwd

image.png

4

cp -r /etc/skel /home/hadoop && chmod 700 /home/hadoop

image.png

5

chown -R hadoop:hadoop /home/hadoop/

image.png

6

cat /proc//meminfo | grep  "^[s,S]"

cat /proc//meminfo | grep -e "^[s|S]"

image.png

image.png

7、

cat /etc/passwd | grep -v "/sbin/nologin\>" | cut -d: -f1

image.png

8、

cat /etc/passwd | grep "/bin/bash\>" | cut -d: -f1

image.png

9、

cat /etc/passwd | grep -E -o "[0-9]{1,2}"

image.png

10、

cat /boot/grub/grub.conf | grep "^[[:space:]]"

cat /boot/grub/grub.conf | grep "^[[:space:]]\+"

image.png

11

cat /etc/rc.d/rc.sysinit | grep "^#[[:space:]]\+[^[:space:]]\+"

cat /etc/rc.d/rc.sysinit | grep -E "^#[[:space:]]+[^[:space:]]+"

image.png

12

netstat -tan | grep -E "LISTEN[[:space:]]*$"

image.png

13

useradd bash && useradd testbash && useradd basher && useradd -s /sbin/nologin nologin |grep -E "^([[:alnum:]]+\>).*\1$" /etc/passwd

image.png

image.png