1.统计出/etc/passwd文件中其默认shell为非/sbin/nologin的用户个数,并将用户都显示出来 cat /etc/passwd| grep -v /sbin/nologin |wc -l cat /etc/passwd | grep -v /sbin/nologin |cut -d: -f1

2.查出用户UID最大值的用户名,uid及shell类型 cat /etc/passwd | cut -d: -f1,3,7 | sort -t: -k2 -nr|head -1

3.统计当前连接本机的每个远程主机IP的连接数,并从大到小排序 w -h | tr -s " "|cut -d " " -f3|sort|uniq -c|sort -nr

4.编写脚本createuser.sh实现如下功能:使用一个用户名做参数,如果指定参数的用户存在,就显示其存在否则添加之,显示添加的用户的id号等信息。 #!/bin/bash

RED="\033[31m" YELLOW="\033[0;33m" RESET="\033[0m" if [ $# -ne 1 ];then echo -e "$RED you must be enter a parameter,only one! $RESET" exit 2 fi

username=$1 id $username &> /dev/null if [ $? -eq 0 ];then echo -e "$YELLOW $username has existed ! $RESET" else useradd $username &> /dev/null fi id $username

5.编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等。 vim /etc/vimrc在里面写入:

set ignorecase set cursorline set autoindent autocmd BufNewFile *.sh exec ":call SetTitle()" func SetTitle() if expand("%:e") == 'sh' call setline(1,"#!/bin/bash") call setline(2,"#") call setline(3,"#") call setline(4,"#Author: sdp") call setline(5,"#QQ: 980976952") call setline(6,"#Date: ".strftime("%Y-%m-%d")) call setline(7,"#FileName: ".expand("%")) call setline(8,"#URL: http://www.magedu.com") call setline(9,"#Description: The test script") call setline(10,"#Copyright (C): ".strftime("%Y")." All rights reserved") call setline(11,"#") call setline(12,"") endif endfunc autocmd BufNewFile * normal G