1.統計出/etc/passwd文件中默認shell爲非/sbin/nologin的用戶個數,並將用戶都顯示出來shell
[20:14:48 root@CentOS7 ~]#cat /etc/passwd |grep -v "/sbin/nologin$" |cut -d: -f1
2.查詢用戶UID最大值的用戶名,uid及shell類型vim
[20:34:59 root@CentOS7 ~]#sort -t: -n -k3 /etc/passwd|tail -1|cut -d: -f1,3,7
3.統計當前鏈接本機的每一個遠程主機IP的鏈接數,並按從大到小排序bash
[20:52:35 root@CentOS7 ~]#netstat -t|grep [0-9]|tr -s " " :|cut -d: -f6|uniq -c|sort -nr
4.編寫腳本createuser.sh 實現以下功能:使用一個用戶名作爲參數,若是指定參數的用戶存在,就顯示其存在,不然添加。顯示添加的用戶的ID號等信息ide
#!/bin/bash COLORB="\033[1;36m" COLORE="\033[0m" read -p "please input a username:" USERNAME id $USERNAME &> /dev/null if [[ $? -eq 0 ]]; then echo "the user is exist" else useradd $USERNAME echo tww |passwd --stdin $USERNAME > /dev/null echo -e "The user is created ,The user's password is:$COLORB tww $COLORE" echo -e "The information of user's id is:$COLORB `id $USERNAME` $COLORE" fi
顯示結果以下:ui
5.編寫生成腳本基本格式的腳本,包括:做者,聯繫方式,版本,時間,描述等spa
將如下代碼寫入家目錄的.vimrc文件中orm
即:vim /boot/.vimrcblog
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: tww") call setline(5,"#QQ: 123456789") call setline(6,"#Date: ".strftime("%Y-%m-%d")) call setline(7,"#FileName: ".expand("%")) call setline(8,"#URL: https://blog.51cto.com/14814545") 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
顯示結果以下:排序