一、
复制/etc/passwd文件到目录中,抓取不是以root开头和结尾的含有root的文件
grep -Ev "^root|root$" passwd | grep root
二、
请显示系统中能被su命令切换的用户名称
grep -E "/bin/bash$|/bin/sh$" /etc/passwd | cut -d : -f 1
三、
练习脚本:
Apache_port.sh,此脚本接入数字,http的端口就改为此数字,假设selinux为关闭状态
例如:
sh Apache_port.sh
ERROR: Pleaase input port number following script !!
sh Apache_port.sh 8080
apache的端口会被修改为8080
vim Apache_port.sh
///
[ -z "$1" ] && {
echo "Error: not port number Please give port following scipt"
exit
}
[ -z "`netstat -antlupe | grep $1`" ] || {
echo "Error: $1 is used by system proto !!"
exit
}
sed "/^Listen/c Listen $1" -i /etc/httpd/conf/httpd.conf
systemctl restart httpd &&{
echo "Confiure port sucessful !!"
}
///
sh Apache_port.sh 8080
四、
awk -F : 'BEGIN{N=0}$6!~/^\/home/&&/bash$|sh$/{N++}END{print N}' /etc/passwd
五、
ps ax -o %mem 统计内存的总共使用量(即全部相加)
ps ax -o %mem | awk 'BEGIN{N=0}!/%MEM|0.0/{N+=$1}END{print N}'